Path: csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed3.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.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'utf-8': 0.07; 'default;': 0.09; 'encode': 0.09; 'mode,': 0.09; 'open()': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'subject:script': 0.09; 'subject:not': 0.11; 'encoding': 0.15; 'codec': 0.16; 'eclipse': 0.16; 'encodings': 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; 'subject:when': 0.16; 'wrote:': 0.17; 'specify': 0.17; 'skip:" 30': 0.20; 'default,': 0.22; 'header:User-Agent:1': 0.26; 'header:X-Complaints-To:1': 0.28; 'character': 0.29; 'no,': 0.29; 'error': 0.30; 'file': 0.32; 'problem': 0.33; 'to:addr:python- list': 0.33; "can't": 0.34; 'changed': 0.34; 'wrong': 0.34; 'skip:l 30': 0.35; 'doing': 0.35; 'something': 0.35; 'received:org': 0.36; 'but': 0.36; 'uses': 0.37; 'subject:: ': 0.38; 'behind': 0.38; 'to:addr:python.org': 0.39; 'header:Received:5': 0.40; 'skip:u 10': 0.60; 'skip:c 50': 0.66; 'now:': 0.71; 'confusion.': 0.84; 'subject:running': 0.84; 'scenes': 0.91 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Peter Otten <__peter__@web.de> Subject: Re: UnicodeEncodeError when not running script from IDE Date: Tue, 12 Feb 2013 16:48:55 +0100 Organization: None References: <650d144e-da3d-4ca7-ad3a-49f44ce9cbaa@googlegroups.com> <0d6d513d-fa12-4d51-a33d-7bb38f1ee6b2@googlegroups.com> <780d353a-de5c-4d04-8f51-11d81802351b@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 7Bit X-Gmane-NNTP-Posting-Host: p5084a602.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: 28 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1360684126 news.xs4all.nl 6944 [2001:888:2000:d::a6]:43385 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:38764 Magnus Pettersson wrote: >> io.open() uses UTF-8 by default, but you can specify other encodings with >> >> io.open(filepath, mode, encoding=whatever). > > > Interesting. Pydev must be doing something behind the scenes because when > i changed open() to io.open() i get error inside of eclipse now: > > f.write(card+"\n") > File "C:\python27\lib\encodings\cp1252.py", line 19, in encode > return codecs.charmap_encode(input,self.errors,encoding_table)[0] > UnicodeEncodeError: 'charmap' codec can't encode character u'\u53c8' in > position 32: character maps to > > .... > > io.open(filepath, "a", encoding="UTF-8") as f: > > Then it works in eclipse. But I seem to be having an encoding problem all > over the place that works in eclipse but dosnt work outside of eclipse > pydev. No, I was wrong about the default; it is actually locale.getpreferredencoding(). Sorry for the confusion.