encoding error in python 27

Peter Otten __peter__ at web.de
Fri Feb 22 10:40:47 EST 2013


Hala Gamal wrote:

> my code works well with english file but when i use text file
> encodede"utf-8" "my file contain some arabic letters" it doesn't work. my
> code:

>   with codecs.open("tt.txt",encoding='utf-8') as txtfile:

Try encoding="utf-8-sig" in the above to remove the byte order mark (BOM) 
upon decoding, see

http://docs.python.org/2.7/library/codecs.html#module-encodings.utf_8_sig

That should prevent

> UnicodeEncodeError: 'decimal' codec can't encode character u'\ufeff' in
> position 0: invalid decimal Unicode string





More information about the Python-list mailing list