print UTF-8 file with BOM

davihigh at gmail.com davihigh at gmail.com
Fri Dec 23 09:57:06 EST 2005


FYI. I had just receive something from a friend, he give me following
nice example!

I have one more question on this: How to write if I want to specify
locale other than current locale? For example, program runn on Korea
locale system, and try reading a UTF-8 file that save chinese
characters.

-------------- The code is here --------------------
import codecs
def read_utf8_txt_file (filename):
    fileObj = codecs.open( filename, "r", "utf-8" )
    content = fileObj.read()
    content = content[1:] #exclude BOM
    print content
    fileObj.close()




More information about the Python-list mailing list