unicode handling

You are sure what file saved in utf-16 encoding?

okay does that mean u cannot open any file with

infile = codecs.open(filename, “r”, encoding=‘utf-16’)

basically I have a txt file with content

···

string MetaDataPrompt = “Discovery No”;
string MetaDataFieldName = “Discovery No”;
string MetaDataType = “string”;
string MetaDataValue = “£500”;

string MetaDataPrompt = “comments”;
string MetaDataFieldName = “Comments”;
string MetaDataType = “string”;
string MetaDataValue = “Energy Scope £500”;


i need to read it into a list

filename=‘d:/poll/test.XST’
f = open(filename, “rb”)
text = f.read().split(‘\n’)

[‘string MetaDataPrompt = “Discovery No”;\r’, ‘\r’, ‘string MetaDataFieldName = “Discovery No”;\r’, ‘\r’, ‘string MetaDataType = “string”;\r’, ‘\r’, ‘string MetaDataValue = “\xa3500”;\r’, ‘\r’, ‘string MetaDataPrompt = “comments”;\r’, ‘\r’, ‘string MetaDataFieldName = “Comments”;\r’, ‘\r’, ‘string MetaDataType = “string”;\r’, ‘\r’, ‘string MetaDataValue = “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: ordinal not in range(128)

so I was thinking I open the file with encoding utf-16 I will have the list populated in unicode… I guess I was wrong…

cheers


Thomas Thomas
thomas@mindz-i.co.nz
Phone. +64 7 855 8478
Fax. +64 7 855 8871