Sorry, I'm newbie in python. I can't help you further, indeed I don't know either.:)<br><br><div><span class="gmail_quote">2005/12/23, David Xiao <<a href="mailto:davihigh@gmail.com">davihigh@gmail.com</a>>:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Hi Kuan:<br><br>Thanks a lot! One more question here: How to write if I want to<br>specify locale other than current locale?<br><br>For example, running on Korea locale system, and try read a UTF-8 file<br>that save chinese.
<br><br>Regards, David<br><br><br><br><br>2005/12/23, Kevin Yuan <<a href="mailto:farproc@gmail.com">farproc@gmail.com</a>>:<br>> import codecs<br>> def read_utf8_txt_file (filename):<br>>     fileObj = codecs.open
( filename, "r", "utf-8" )<br>>     content = fileObj.read()<br>>     content = content[1:] #exclude BOM<br>>     print content<br>>      fileObj.close()<br>><br>> read_utf8_txt_file("e:\\u.txt")
<br>><br>> 22 Dec 2005 18:12:28 -0800, <a href="mailto:davihigh@gmail.com">davihigh@gmail.com</a> < <a href="mailto:davihigh@gmail.com">davihigh@gmail.com</a>>:<br>> > Hi Friends:<br>> ><br>> >         fileObj = 
codecs.open( filename, "r", "utf-8" )<br>> >         u = fileObj.read() # Returns a Unicode string from the UTF-8 bytes<br>> in<br>> > the file<br>> >         print u<br>> ><br>
> > It says error:<br>> >         UnicodeEncodeError: 'gbk' codec can't encode character u'\ufeff'<br>> in<br>> > position 0:<br>> >         illegal multibyte sequence<br>> ><br>> > I want to know how read from UTF-8 file, and convert to specified
<br>> > locale (default is current system locale) and print out string. I hope<br>> > put away BOM header automatically.<br>> ><br>> > Rgds, David<br>> ><br>> > --<br>> > <a href="http://mail.python.org/mailman/listinfo/python-list">
http://mail.python.org/mailman/listinfo/python-list</a><br>> ><br>><br>><br></blockquote></div><br>