/ Published in: Python

Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
import sys from codecs import EncodedFile ## EncodedFile "wraps" stdout so that it always takes a "from_encoding" string and ## convert it to a "to_encoding" string from_encoding = 'big5' to_encoding = 'utf8' sys.stdout = EncodedFile(sys.stdout, from_encoding, to_encoding) ## read a file in big5 encoding f = file("foo.html", "r") str = f.read() ## print the content of the file in utf8 sys.stdout.write(str) # you can also use "print str"
Comments
