[Tutor] unichr not working as expected
eryksun
eryksun at gmail.com
Mon Jul 22 20:55:12 CEST 2013
On Mon, Jul 22, 2013 at 2:14 PM, Jim Mooney <cybervigilante at gmail.com> wrote:
> I tried translating the odd chars I found in my dos tree /f listing to
> symbols, but I'm getting this error. The chars certainly aren't over 10000,
> The ord is only 13 - so what's wrong here?
>
> def main():
> zark = ''
> for x in "ÀÄÄÄ":
> zark += unichr(ord(x)-45)
>
> print(zark)
>
> unichr() arg not in range(0x10000) (narrow Python build)
13 is a carriage return (i.e. '\r'). That's giving you a negative
result when you subtract 45. By the way, why are you doing that?
The characters shown in your string are 195 (0xC3) and 196 (0xC4) in
cp1252. Refer to the following chart for their value as cp437 box
drawing characters:
http://en.wikipedia.org/wiki/Box-drawing_character#DOS
Also, the upper limit for Unicode ordinals on a narrow build is
0x10000, not 10000. In a narrow build, you get the 16-bit basic
multilingual plane (BMP). \U literals that are above that produce
UTF-16 surrogate pairs.
More information about the Tutor
mailing list