Python Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesPython Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old March 20th, 2004, 01:53 PM
sonatas sonatas is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2004
Posts: 9 sonatas User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Exclamation python character map range

I have the basics for making the character map but I cant seem to get the range to work...

I keep on getting some weird int or str error no matter what I try.

There are 2 files. The first is an html file that acts as a form. The second is the .py program

Can someone help me figure out how to get the program to have the range that was inputted from file 1 appear onto file 2? And, I want to have a limit to that range...that is even if someone typed in 400-900, i want just 400-500 to appear.

All you have to do is convert file 1 into html and file 2 into .py

The range that i had is not in the .py file because it keeps on having errors...
for i in range (int(["start"],["end"]))
print unichr(i)
Attached Files
File Type: txt file1.txt (585 Bytes, 651 views)
File Type: txt file2.txt (1.8 KB, 558 views)

Reply With Quote
  #2  
Old March 20th, 2004, 03:04 PM
sonatas sonatas is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2004
Posts: 9 sonatas User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
I can only find the range for the first and last character now...
what i did was i copy and pasted the start table and made another one but for every start, i changed it to end....
i jus still cant get the stuff in between

Reply With Quote
  #3  
Old March 20th, 2004, 07:40 PM
Grim Archon's Avatar
Grim Archon Grim Archon is offline
Mini me.
Dev Shed Novice (500 - 999 posts)
 
Join Date: Nov 2003
Location: Cambridge, UK
Posts: 783 Grim Archon User rank is Corporal (100 - 500 Reputation Level)Grim Archon User rank is Corporal (100 - 500 Reputation Level)Grim Archon User rank is Corporal (100 - 500 Reputation Level)Grim Archon User rank is Corporal (100 - 500 Reputation Level)  Folding Points: 1488 Folding Title: Novice Folder
Time spent in forums: 3 Days 2 h 15 m 57 sec
Reputation Power: 12
Send a message via MSN to Grim Archon
I haven't tested it but something like this?
Code:
end = int(form["end"].value)
if end > 500: 
    end = 500
char = int(form["start"].value)
while char <= end: 
    print '<tr>'
    print '<td class="num">'+str(char)+'</td>'
    print '<td><code class="html">&#%03d;</code></td>'%(char, )
    print '<td class="char"><span>&#%03d;</span></td>'%(char, )
    print '<td class="name">%s</td>'%(unicodedata.name(unichr(char)), )
    print '</tr>'
    char = char+1
print '</tbody>'


Grim
__________________
*** Experimental Python Markup CGI V2 ***

Reply With Quote
  #4  
Old March 20th, 2004, 08:47 PM
netytan's Avatar
netytan netytan is offline
Hello World :)
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Mar 2003
Location: Hull, UK
Posts: 2,537 netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 1 Week 2 Days 18 h 17 m 47 sec
Reputation Power: 68
Send a message via ICQ to netytan Send a message via AIM to netytan Send a message via MSN to netytan Send a message via Yahoo to netytan
Another untested code snippet using a for loop and range() this time (based on grims code).

Code:
print '<table>'

start = int(form['start'].value)
end = int(form['end'].value)

for each in range(start, end):
    print '<tr>'
    print '<td class="num">%s</td>' % each
    print '<td class="html">&#%03d;</td>' % each
    print '<td class="char">&#%03d;</td>' % each
    print '<td class="name">%s</td>' % unicodedata.name(unichr(each))
    print '</tr>'
    
    if each == 500:
        break
    
print '</table>'


Hope this is of some help,

Mark.
__________________
programming language development: www.netytan.com Hula


Reply With Quote
  #5  
Old March 20th, 2004, 09:24 PM
sonatas sonatas is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2004
Posts: 9 sonatas User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Quote:
Originally Posted by Grim Archon
I haven't tested it but something like this?
Code:
end = int(form["end"].value)
if end > 500: 
    end = 500
char = int(form["start"].value)
while char <= end: 
    print '<tr>'
    print '<td class="num">'+str(char)+'</td>'
    print '<td><code class="html">&#%03d;</code></td>'%(char, )
    print '<td class="char"><span>&#%03d;</span></td>'%(char, )
    print '<td class="name">%s</td>'%(unicodedata.name(unichr(char)), )
    print '</tr>'
    char = char+1
print '</tbody>'


Grim


what if i wanted to have a limit of just 100 characters appearing even when someone asks for 300? I didn't mean that the characters only goes up to #100

Reply With Quote
  #6  
Old March 21st, 2004, 02:27 AM
Grim Archon's Avatar
Grim Archon Grim Archon is offline
Mini me.
Dev Shed Novice (500 - 999 posts)
 
Join Date: Nov 2003
Location: Cambridge, UK
Posts: 783 Grim Archon User rank is Corporal (100 - 500 Reputation Level)Grim Archon User rank is Corporal (100 - 500 Reputation Level)Grim Archon User rank is Corporal (100 - 500 Reputation Level)Grim Archon User rank is Corporal (100 - 500 Reputation Level)  Folding Points: 1488 Folding Title: Novice Folder
Time spent in forums: 3 Days 2 h 15 m 57 sec
Reputation Power: 12
Send a message via MSN to Grim Archon
Something like:
Code:
if end - char >100:
    end = char+100


Grim

Reply With Quote
  #7  
Old March 21st, 2004, 07:33 AM
netytan's Avatar
netytan netytan is offline
Hello World :)
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Mar 2003
Location: Hull, UK
Posts: 2,537 netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 1 Week 2 Days 18 h 17 m 47 sec
Reputation Power: 68
Send a message via ICQ to netytan Send a message via AIM to netytan Send a message via MSN to netytan Send a message via Yahoo to netytan
Surly you would just alter the limit?I could be being really dumb though .

Code:
print '<table>'

limit = 100

start = int(form['start'].value)
end = int(form['end'].value)

for each in xrange(start, end):
    print '<tr>'
    print '<td class="num">%s</td>' % each
    print '<td class="html">&#%03d;</td>' % each
    print '<td class="char">&#%03d;</td>' % each
    print '<td class="name">%s</td>' % unicodedata.name(unichr(each))
    print '</tr>'
    
    if each == limit:
        break
    
print '</table>'


Or in grims example (just to show Grims code snippet in context)...

Code:
end = int(form["end"].value)
char = int(form["start"].value)
if end - char > 100: 
    end = char + 100
while char <= end: 
    print '<tr>'
    print '<td class="num">'+str(char)+'</td>'
    print '<td><code class="html">&#%03d;</code></td>'%(char, )
    print '<td class="char"><span>&#%03d;</span></td>'%(char, )
    print '<td class="name">%s</td>'%(unicodedata.name(unichr(char)), )
    print '</tr>'
    char = char+1
print '</tbody>'


In both these examples the char range cant exceed the set limit (100).

note: still untested

edit: changed range() to xrange(), this makes little difference to the current example but with huge numbers it saves Python from creating a new list in memory (which can lead to memory errors in very extream cases).

Mark.

Last edited by netytan : March 21st, 2004 at 07:49 AM.

Reply With Quote
  #8  
Old March 21st, 2004, 01:56 PM
sonatas sonatas is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2004
Posts: 9 sonatas User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
wow....ty.....but how come there's an error from characters 0-31?

Reply With Quote
  #9  
Old March 21st, 2004, 03:36 PM
netytan's Avatar
netytan netytan is offline
Hello World :)
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Mar 2003
Location: Hull, UK
Posts: 2,537 netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 1 Week 2 Days 18 h 17 m 47 sec
Reputation Power: 68
Send a message via ICQ to netytan Send a message via AIM to netytan Send a message via MSN to netytan Send a message via Yahoo to netytan
How do you mean an error? Pythons giving you an error message or are the characters just not showing right? If its the latter i'd guess its because those numbers dont have any related characters i.e.

Code:
>>> for each in range(100):
...     print chr(each),
...     
         	

                    ! " # $ % & ' ( ) * + , - . / 0 1 2 3 4 5 6 7 8 9 : ; < = > ? @ A B C D E F G H I J K L M N O P Q R S T U V W X Y Z [ \ ] ^ _ ` a b c
>>>


Note: If you have wxPython try running that in the PyShell and it will replace the boxes by there char's. In IDLE you'll get the boxes as above.

Mark.

Reply With Quote
  #10  
Old March 21st, 2004, 05:33 PM
sonatas sonatas is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2004
Posts: 9 sonatas User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
in python it works great.....but when I put it on the web...

First character 0
Last character 200

there will be an error instead of having just the 32-132 characters appearing

I tried using something like:
name=unicodedata.name(unichr(char), "undefined")
if name!="undefined":

but it just crashes the page lol

Reply With Quote
  #11  
Old March 21st, 2004, 09:12 PM
netytan's Avatar
netytan netytan is offline
Hello World :)
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Mar 2003
Location: Hull, UK
Posts: 2,537 netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 1 Week 2 Days 18 h 17 m 47 sec
Reputation Power: 68
Send a message via ICQ to netytan Send a message via AIM to netytan Send a message via MSN to netytan Send a message via Yahoo to netytan
Mmmm, i'm a little unsure as to whats going on. Do you have an example i could mabe look at? Also, if you have access to the server maybe you could tell me what errors your getting in your error log.

But maybe i should download the two files that i seem to have over looked

Anyway its late, night all.

Mark.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPython Programming > python character map range

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap