unicode handling
Thomas Thomas
thomas at mindz-i.co.nz
Wed Aug 2 19:39:44 PDT 2006
Hi all,
I have a file with special characters such as "=A3" etc. I need to read th=
e file into a list as unicode strings..
How can I do this.. I tried codecs =
import codecs
filename=3D'd:/poll/test.XST'
metaHash=3D{}
infile =3D codecs.open(filename, "r", encoding=3D'utf-16')
text =3D 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 =3D 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 =3D "Discovery No";
string MetaDataFieldName =3D "Discovery No";
string MetaDataType =3D "string";
string MetaDataValue =3D "=A3500";
}
3{
string MetaDataPrompt =3D "comments";
string MetaDataFieldName =3D "Comments";
string MetaDataType =3D "string";
string MetaDataValue =3D "Energy Scope =A3500";
I know I should have asked this on python-list and not on wxpython .. But w=
hen "=A3" is entered through the gui everything is working fine. But when I=
try reading it from a file I am having problems. So I thought I will try i=
n here as well
any luck
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://lists.wxwidgets.org/pipermail/wxpython-users/attachments/200608=
03/3c50bae8/attachment.htm
More information about the wxpython-users
mailing list