|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
AT&T devCentral & BlackBerry(r) Webcast Series: BlackBerry and GPS -Build Location Awareness into your BlackBerry Applications, July 10th-1:00PM EST. Register Today!
|
|
#1
|
|||
|
|||
|
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) |
|
#2
|
|||
|
|||
|
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 ![]() |
|
#3
|
||||
|
||||
|
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 *** |
|
#4
|
||||
|
||||
|
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. |
|
#5
|
|||
|
|||
|
Quote:
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 |
|
#6
|
||||
|
||||
|
Something like:
Code:
if end - char >100:
end = char+100
![]() Grim |
|
#7
|
||||
|
||||
|
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. |
|
#8
|
|||
|
|||
|
wow....ty.....but how come there's an error from characters 0-31?
|
|
#9
|
||||
|
||||
|
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. |
|
#10
|
|||
|
|||
|
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") but it just crashes the page lol |
|
#11
|
||||
|
||||
|
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. |
![]() |
| Viewing: Dev Shed Forums > Programming Languages > Python Programming > python character map range |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|