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 what SHOULD work, maybe I can diagnose this
problem.


with a minor fix (import sys) that runs without errors in Python 3.1 (Vista), but the result is a bit disturbing...

--------------------------
晉
Content-type:text/plain;charset=utf-8
<BLANKLINE>
<BLANKLINE>
--------------------------

(is this a bug? or just undefined behavior?)



the following works correctly in python 3.1:

---------------------------
#!/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')
----------------------------

(and that code will definitely fail with python2 because of the print assignment, an insurance if your server happens to be misconfigured to run python2)
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to