Path: csiph.com!usenet.pasdenom.info!goblin2!goblin.stu.neva.ru!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.002 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; '"my': 0.09; 'encode': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'subject:error': 0.11; 'subject:python': 0.11; 'codec': 0.16; 'received:80.91.229.3': 0.16; 'received:dip.t-dialin.net': 0.16; 'received:plane.gmane.org': 0.16; 'received:t-dialin.net': 0.16; 'string': 0.17; 'wrote:': 0.17; 'byte': 0.17; 'unicode': 0.17; 'work.': 0.23; 'header:User-Agent:1': 0.26; 'prevent': 0.27; "doesn't": 0.28; 'header:X-Complaints-To:1': 0.28; 'decimal': 0.29; 'character': 0.29; 'code': 0.31; 'url:python': 0.32; 'file': 0.32; 'to:addr:python-list': 0.33; 'code:': 0.33; "can't": 0.34; 'text': 0.34; 'received:org': 0.36; 'but': 0.36; 'url:org': 0.36; 'url:library': 0.36; 'should': 0.36; 'subject:: ': 0.38; 'mark': 0.38; 'some': 0.38; 'url:docs': 0.38; 'to:addr:python.org': 0.39; 'header:Received:5': 0.40; 'skip:u 10': 0.60; 'remove': 0.61 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Peter Otten <__peter__@web.de> Subject: Re: encoding error in python 27 Date: Fri, 22 Feb 2013 16:40:47 +0100 Organization: None References: Mime-Version: 1.0 Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 7Bit X-Gmane-NNTP-Posting-Host: p5084bbce.dip.t-dialin.net User-Agent: KNode/4.7.3 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 19 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1361547628 news.xs4all.nl 6866 [2001:888:2000:d::a6]:51955 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:39581 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