Movatterモバイル変換
[0]ホーム
Jython: Upper-ASCII characters '\351' from chr(233)
D-Mandsh8290 at rit.edu
Fri Apr 20 17:27:36 EDT 2001
On Fri, Apr 20, 2001 at 09:45:33PM +0100, Maurice Bauhahn wrote:| Thank you for the suggestion, D-Man.|| However, I doubt that this is a problem with the display, because I| can see all these unusual characters when I print a line of text to| the screen. The problem becomes obvious when I try one of those| upper ASCII characters as a key of the dictionary...it does not| work. My hope is to compare each character from a text file...andHow do you know it doesn't work? I have heard that all strings inJython are Unicode because all Java strings are Unicode (or somethinglike that).Say...I just tried it again, using Jython 2.0 and CPython 2.1. If Itypeprint chr( 233 )I get an accented e in CPython and something else from Jython, but notthe '\351' from before. Actually in CPython I get '\xe9' if I justcall chr. It might be a difference between str() and repr().If you can enter the character into your file, putting a 'u' in frontof the string specifies it as unicode. Ex :print u'é'Say, what if you use the 'unichr' function? There might be adifference between chr and unichr (in CPython there is).Here is a snippet, CPython first, then Jython :>>> unichr( 8218 )u'\u201a'>>> print unichr( 8218 )Traceback (most recent call last): File "<stdin>", line 1, in ?UnicodeError: ASCII encoding error: ordinal not in range(128)>>> ord( 'é' )8218>>> unichr( 233 )'\351'>>> unichr( 8218 )u'\u201A'>>> print unichr( 8218 )é>>> print chr( 8218 )é| use the dictionary to assist in translation of those characters to| Unicode (the Cambodian script...so standard Java code converters are| not useful).|| Maybe I will have to call a Java function to accomplish my desired| task, right?Maybe. I really don't have much experience with using Unicode orlocale specific stuff.I hope my results give you some thoughts on how to solve your problem.-D
More information about the Python-listmailing list
[8]ページ先頭