#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2004
    Posts
    9
    Rep 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
  2. #2
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2004
    Posts
    9
    Rep 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
  4. #3
  5. Mini me.
    Devshed Novice (500 - 999 posts)

    Join Date
    Nov 2003
    Location
    Cambridge, UK
    Posts
    783
    Rep Power
    13
    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">&amp;#%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
  6. #4
  7. Hello World :)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2003
    Location
    Hull, UK
    Posts
    2,537
    Rep Power
    69
    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">&amp;#%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

  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2004
    Posts
    9
    Rep Power
    0
    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">&amp;#%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
  10. #6
  11. Mini me.
    Devshed Novice (500 - 999 posts)

    Join Date
    Nov 2003
    Location
    Cambridge, UK
    Posts
    783
    Rep Power
    13
    Something like:
    Code:
    if end - char >100:
        end = char+100

    Grim
  12. #7
  13. Hello World :)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2003
    Location
    Hull, UK
    Posts
    2,537
    Rep Power
    69
    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">&amp;#%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">&amp;#%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.
    programming language development: www.netytan.com Hula

  14. #8
  15. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2004
    Posts
    9
    Rep Power
    0
    wow....ty.....but how come there's an error from characters 0-31?
  16. #9
  17. Hello World :)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2003
    Location
    Hull, UK
    Posts
    2,537
    Rep Power
    69
    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.
    programming language development: www.netytan.com Hula

  18. #10
  19. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2004
    Posts
    9
    Rep 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
  20. #11
  21. Hello World :)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2003
    Location
    Hull, UK
    Posts
    2,537
    Rep Power
    69
    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.
    programming language development: www.netytan.com Hula


IMN logo majestic logo threadwatch logo seochat tools logo