Help needed with python unicode cgi-bin script
weheh
weheh at verizon.net
Tue Dec 11 19:06:09 EST 2007
p.s. I modified the code to break things out more explicitly:
#!C:/Program Files/Python23/python.exe
import cgi, cgitb
import sys, codecs
import os,msvcrt
cgitb.enable()
print u"""Content-Type: text/html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" >
<html xmlns="http://www.w3.org/1999/xhtml" lang="en,sp,fr"
xml:lang="en,sp,fr">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf8" />
<meta http-equiv="content-language" content="en,fr,sp" />
</head>
<body>
"""
if sys.platform == 'win32':
msvcrt.setmode(sys.stdin.fileno(), os.O_BINARY)
msvcrt.setmode(sys.stdout.fileno(), os.O_BINARY)
x = open('c:/test/spanish.txt','rb').read()
print '<p>',x,'# first print</p>'
x = open('c:/test/spanish.txt','rb').read()
x = repr(x)
print '<p>',x,'# second print</p>'
x = open('c:/test/spanish.txt','rb').read()
x = repr(x)
x = x.decode('windows-1252')
print '<p>',x,'# third print</p>'
x = open('c:/test/spanish.txt','rb').read()
x = repr(x)
x = x.decode('windows-1252')
x = x.encode('utf8')
print '<p>',x,'# third print</p>'
print """
</body>
</html>
"""
(The last print should read "fourth print")
More information about the Python-list
mailing list