Re: Can't print Chinese to HTTP

2009-12-06 Thread Dave Angel
Gnarlodious wrote: On Dec 5, 3:54 am, Lie Ryan wrote: Because of the switch to unicode str, a simple print('晉') should've worked flawlessly if your terminal can accept the character, but the problem is your terminal does not. There is nothing wrong with Terminal, Mac OSX supports Unic

Re: Can't print Chinese to HTTP

2009-12-05 Thread Lie Ryan
On 12/6/2009 12:56 PM, Gnarlodious wrote: On Dec 5, 3:54 am, Lie Ryan wrote: Because of the switch to unicode str, a simple print('晉') should've worked flawlessly if your terminal can accept the character, but the problem is your terminal does not. There is nothing wrong with Terminal, Mac OS

Re: Can't print Chinese to HTTP

2009-12-05 Thread Gnarlodious
On Dec 5, 3:54 am, Lie Ryan wrote: > Because of the switch to unicode str, a simple print('晉') should've > worked flawlessly if your terminal can accept the character, but the > problem is your terminal does not. There is nothing wrong with Terminal, Mac OSX supports Unicode from one end to the o

Re: Can't print Chinese to HTTP

2009-12-05 Thread Alf P. Steinbach
* Lie Ryan: On 12/5/2009 2:57 PM, Gnarlodious wrote: On Dec 1, 3:06 pm, Terry Reedy wrote: def print(s): return sys.stdout.buffer.write(s.encode('utf-8')) Here is a better solution that lets me send any string to the function: def print(html): return sys.stdout.buffer.write(("Content-type:te

Re: Can't print Chinese to HTTP

2009-12-05 Thread Lie Ryan
On 12/5/2009 2:57 PM, Gnarlodious wrote: On Dec 1, 3:06 pm, Terry Reedy wrote: def print(s): return sys.stdout.buffer.write(s.encode('utf-8')) Here is a better solution that lets me send any string to the function: def print(html): return sys.stdout.buffer.write(("Content-type:text/ plain;cha

Re: Can't print Chinese to HTTP

2009-12-04 Thread Gnarlodious
On Dec 1, 3:06 pm, Terry Reedy wrote: > def print(s): return sys.stdout.buffer.write(s.encode('utf-8')) Here is a better solution that lets me send any string to the function: def print(html): return sys.stdout.buffer.write(("Content-type:text/ plain;charset=utf-8\n\n"+html).encode('utf-8')) Why

Re: Can't print Chinese to HTTP

2009-12-04 Thread Gnarlodious
On Dec 2, 11:58 pm, Dennis Lee Bieber wrote: >         Have you tried > >         sys.stdout.write("Content-type:text/plain;charset=utf-8\r\n\r\n") Yes I tried that when it was suggested, to no avail. All I get is "Internal server error". All I can imagine is that there is no "sys.stdout.write" i

Re: Can't print Chinese to HTTP

2009-12-02 Thread Gnarlodious
On Nov 30, 5:53 am, "Martin v. Löwis" wrote: > #!/usr/bin/python > print("Content-type:text/plain;charset=utf-8\n\n") > sys.stdout.buffer.write('晉\n'.encode("utf-8")) Does this work for anyone? Because all I get is a blank page. Nothing. If I can establish what SHOULD work, maybe I can diagnose t

Re: Can't print Chinese to HTTP

2009-12-01 Thread Terry Reedy
Gnarlodious wrote: On Dec 1, 8:36 am, Lie Ryan wrote: #!/usr/bin/python import sys print = lambda s: sys.stdout.buffer.write(s.encode('utf-8')) This is almost exactly the same as def print(s): return sys.stdout.buffer.write(s.encode('utf-8')) except that the latter gives better error traceb

Re: Can't print Chinese to HTTP

2009-12-01 Thread Ned Deily
In article , Gnarlodious wrote: > I symlinked to the new Python, and no I do not want to roll it back > because it is work (meaning I would have to type "sudo"). > ls /usr/bin/python > lrwxr-xr-x 1 root wheel 63 Nov 20 21:24 /usr/bin/python -> /Library/ > Frameworks/Python.framework/Versions

Re: Can't print Chinese to HTTP

2009-12-01 Thread Gnarlodious
On Dec 1, 8:36 am, Lie Ryan wrote: > #!/usr/bin/python > import sys > print = lambda s: sys.stdout.buffer.write(s.encode('utf-8')) > print("Content-type:text/plain;charset=utf-8\n\n") > print('晉\n') HA! IT WORKS! Thank you thank you thank you. I don't understand the lambda functionality but will

Re: Can't print Chinese to HTTP

2009-12-01 Thread Lie Ryan
On 12/2/2009 12:27 AM, Gnarlodious wrote: On Nov 30, 5:53 am, "Martin v. Löwis" wrote: #!/usr/bin/python print("Content-type:text/plain;charset=utf-8\n\n") sys.stdout.buffer.write('晉\n'.encode("utf-8")) Does this work for anyone? Because all I get is a blank page. Nothing. If I can establish

Re: Can't print Chinese to HTTP

2009-11-30 Thread Gnarlodious
> you probably need to change the encoding of sys.stdout >>> sys.stdout.encoding 'UTF-8' >> #!/usr/bin/python > do you know what python version, exactly, that gets called by this hashbang? Verified in HTTP: >>> print(sys.version) 3.1.1 Is is possible modules are getting loaded from my old Python?

Re: Can't print Chinese to HTTP

2009-11-30 Thread exarkun
On 05:05 pm, gnarlodi...@gmail.com wrote: Thanks for the help, but it doesn't work. All I get is an error like: UnicodeEncodeError: 'ascii' codec can't encode character '\\u0107' in position 0: ordinal not in range(128) It does work in Terminal interactively, after I import the sys module. But

Re: Can't print Chinese to HTTP

2009-11-30 Thread Ned Deily
In article , Gnarlodious wrote: > It does work in Terminal interactively, after I import the sys module. > But my script doesn't act the same. Here is my entire script: > > #!/usr/bin/python > print("Content-type:text/plain;charset=utf-8\n\n") > import sys > sys.stdout.buffer.write('ùÁÄn'.enco

Re: Can't print Chinese to HTTP

2009-11-30 Thread Lie Ryan
On 12/1/2009 4:05 AM, Gnarlodious wrote: Thanks for the help, but it doesn't work. All I get is an error like: UnicodeEncodeError: 'ascii' codec can't encode character '\\u0107' in position 0: ordinal not in range(128) The error says it all; you're trying to encode the chinese character using

Re: Can't print Chinese to HTTP

2009-11-30 Thread Aahz
In article , Gnarlodious wrote: > >Thanks for the help, but it doesn't work. All I get is an error like: > >UnicodeEncodeError: 'ascii' codec can't encode character '\\u0107' in >position 0: ordinal not in range(128) No time to give you more info, but you probably need to change the encoding of

Re: Can't print Chinese to HTTP

2009-11-30 Thread Gnarlodious
Thanks for the help, but it doesn't work. All I get is an error like: UnicodeEncodeError: 'ascii' codec can't encode character '\\u0107' in position 0: ordinal not in range(128) It does work in Terminal interactively, after I import the sys module. But my script doesn't act the same. Here is my e

Re: Can't print Chinese to HTTP

2009-11-30 Thread Martin v. Löwis
Gnarlodious wrote: > Hello. The "upgrade to Python 3.1 has been disaster so far. I can't > figure out how to print Chinese to a browser. If my script is: > > #!/usr/bin/python > print("Content-type:text/html\n\n") > print('晉') > > the Chinese string simply does not print. It works in interactive

Can't print Chinese to HTTP

2009-11-30 Thread Gnarlodious
Hello. The "upgrade to Python 3.1 has been disaster so far. I can't figure out how to print Chinese to a browser. If my script is: #!/usr/bin/python print("Content-type:text/html\n\n") print('晉') the Chinese string simply does not print. It works in interactive Terminal no problem, and also wo