The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages
> Python Programming
|
python character map range
Discuss python character map range in the Python Programming forum on Dev Shed. python character map range Python Programming forum discussing coding techniques, tips and tricks, and Zope related information. Python was designed from the ground up to be a completely object-oriented programming language.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

March 20th, 2004, 01:53 PM
|
|
Registered User
|
|
Join Date: Mar 2004
Posts: 9
Time spent in forums: < 1 sec
Reputation Power: 0
|
|
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)
|

March 20th, 2004, 03:04 PM
|
|
Registered User
|
|
Join Date: Mar 2004
Posts: 9
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 
|

March 20th, 2004, 07:40 PM
|
 |
Mini me.
|
|
Join Date: Nov 2003
Location: Cambridge, UK
|
|
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
|

March 20th, 2004, 08:47 PM
|
 |
Hello World :)
|
|
Join Date: Mar 2003
Location: Hull, UK
|
|
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
|

March 20th, 2004, 09:24 PM
|
|
Registered User
|
|
Join Date: Mar 2004
Posts: 9
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
|

March 21st, 2004, 02:27 AM
|
 |
Mini me.
|
|
Join Date: Nov 2003
Location: Cambridge, UK
|
|
Something like:
Code:
if end - char >100:
end = char+100

Grim
|

March 21st, 2004, 07:33 AM
|
 |
Hello World :)
|
|
Join Date: Mar 2003
Location: Hull, UK
|
|
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.
|

March 21st, 2004, 01:56 PM
|
|
Registered User
|
|
Join Date: Mar 2004
Posts: 9
Time spent in forums: < 1 sec
Reputation Power: 0
|
|
|
wow....ty.....but how come there's an error from characters 0-31?
|

March 21st, 2004, 03:36 PM
|
 |
Hello World :)
|
|
Join Date: Mar 2003
Location: Hull, UK
|
|
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.
|

March 21st, 2004, 05:33 PM
|
|
Registered User
|
|
Join Date: Mar 2004
Posts: 9
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
|

March 21st, 2004, 09:12 PM
|
 |
Hello World :)
|
|
Join Date: Mar 2003
Location: Hull, UK
|
|
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.
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|