python unicode how to
Thomas Thomas
thomas at mindz-i.co.nz
Wed Aug 2 22:22:15 EDT 2006
Hi all,
I have a file with special characters such as "£" etc. I need to read the file into a list as unicode strings..
How can I do this.. I tried codecs
import codecs
filename='d:/poll/test.XST'
metaHash={}
infile = codecs.open(filename, "r", encoding='utf-16')
text = infile.read().split('\n')
print text
I am getting the error
Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "c:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/python-1928Lij.py", line 9, in ?
text = infile.read().split('\n')
File "C:\Python23\lib\codecs.py", line 380, in read
return self.reader.read(size)
File "C:\Python23\lib\encodings\utf_16.py", line 48, in read
raise UnicodeError,"UTF-16 stream does not start with BOM"
UnicodeError: UTF-16 stream does not start with BOM
also a sample file content will be
string MetaDataPrompt = "Discovery No";
string MetaDataFieldName = "Discovery No";
string MetaDataType = "string";
string MetaDataValue = "£500";
}
3{
string MetaDataPrompt = "comments";
string MetaDataFieldName = "Comments";
string MetaDataType = "string";
string MetaDataValue = "Energy Scope £500";
Thanks
Thomas
-----------------------------------------------------
Thomas Thomas
thomas at mindz-i.co.nz
Phone. +64 7 855 8478
Fax. +64 7 855 8871
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20060803/e8ccee7a/attachment.html>
More information about the Python-list
mailing list