[wxPython-users] unicode handling
Thomas Thomas
thomas at mindz-i.co.nz
Wed Aug 2 21:03:23 PDT 2006
>You are sure what file saved in utf-16 encoding?
okay does that mean u cannot open any file with
infile =3D codecs.open(filename, "r", encoding=3D'utf-16')
basically I have a txt file with content =
---------------------------------------------------------------------------=
---------------
string MetaDataPrompt =3D "Discovery No";
string MetaDataFieldName =3D "Discovery No";
string MetaDataType =3D "string";
string MetaDataValue =3D "=A3500";
string MetaDataPrompt =3D "comments";
string MetaDataFieldName =3D "Comments";
string MetaDataType =3D "string";
string MetaDataValue =3D "Energy Scope =A3500";
-------------------------------------------------------------
i need to read it into a list
filename=3D'd:/poll/test.XST'
f =3D open(filename, "rb")
text =3D f.read().split('\n')
['string MetaDataPrompt =3D "Discovery No";\r', '\r', 'string MetaDataField=
Name =3D "Discovery No";\r', '\r', 'string MetaDataType =3D "string";\r', '=
\r', 'string MetaDataValue =3D "\xa3500";\r', '\r', 'string MetaDataPrompt =
=3D "comments";\r', '\r', 'string MetaDataFieldName =3D "Comments";\r', '\r=
', 'string MetaDataType =3D "string";\r', '\r', 'string MetaDataValue =3D "=
Energy Scope \xa3500";\r', '']
but the list values have to be in unicode otherwise I am getting the error
UnicodeDecodeError: 'ascii' codec can't decode byte 0xa3 in position 24: or=
dinal not in range(128)
so I was thinking I open the file with encoding utf-16 I will have the lis=
t populated in unicode.. I guess I was wrong..
cheers
-----------------------------------------------------
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/bbe84eb8/attachment.htm
More information about the wxpython-users
mailing list