Path: csiph.com!usenet.pasdenom.info!news.albasani.net!newsfeed.freenet.ag!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!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; 'cpython': 0.05; 'scripts': 0.09; 'python': 0.09; 'encode': 0.09; 'subject:script': 0.09; 'to:addr:comp.lang.python': 0.09; 'cc:addr:python-list': 0.10; 'gui': 0.11; 'subject:not': 0.11; '(but': 0.15; '.txt': 0.16; 'ball.': 0.16; 'codec': 0.16; 'eclipse': 0.16; 'fine.': 0.16; 'instead:': 0.16; 'ordinal': 0.16; 'printing.': 0.16; 'subject:when': 0.16; 'wrote:': 0.17; 'fix': 0.17; 'exists': 0.17; 'projects,': 0.17; 'unicode': 0.17; 'windows': 0.19; 'skip:" 40': 0.20; 'trying': 0.21; 'cc:2**0': 0.23; 'errors': 0.23; 'script': 0.24; 'tried': 0.25; 'cc:addr:python.org': 0.25; 'header:In-Reply- To:1': 0.25; 'header:User-Agent:1': 0.26; '(which': 0.26; 'andrew': 0.27; 'disk': 0.27; 'errors.': 0.27; "doesn't": 0.28; 'this?': 0.28; 'fine': 0.28; 'run': 0.28; 'appending': 0.29; 'case,': 0.29; 'character': 0.29; 'probably': 0.29; 'usually': 0.30; 'writes': 0.30; 'error': 0.30; 'code': 0.31; 'file': 0.32; 'running': 0.32; 'could': 0.32; 'print': 0.32; 'says': 0.33; 'handle': 0.33; "can't": 0.34; 'received:google.com': 0.34; 'open': 0.35; "won't": 0.35; 'received:209.85': 0.35; 'skip:u 20': 0.36; 'but': 0.36; '12,': 0.36; 'characters': 0.36; "didn't": 0.36; "i'll": 0.36; 'turn': 0.36; 'does': 0.37; 'received:209': 0.37; 'subject:: ': 0.38; 'supports': 0.38; 'some': 0.38; 'page': 0.38; 'bottom': 0.60; 'skip:u 10': 0.60; 'card': 0.62; 'skip:6 10': 0.63; 'within': 0.64; 'dont': 0.64; 'here': 0.65; 'special': 0.73; 'chinese': 0.78; '(standard': 0.84; '2013': 0.84; 'subject:running': 0.84 X-Received: by 10.49.75.9 with SMTP id y9mr1275926qev.9.1360679061645; Tue, 12 Feb 2013 06:24:21 -0800 (PST) Newsgroups: comp.lang.python Date: Tue, 12 Feb 2013 06:24:21 -0800 (PST) In-Reply-To: Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=46.9.253.222; posting-account=rbrw_goAAADkxBdp_kDLn3mjmxW9-buk References: <650d144e-da3d-4ca7-ad3a-49f44ce9cbaa@googlegroups.com> User-Agent: G2/1.0 X-Google-Web-Client: true X-Google-IP: 46.9.253.222 MIME-Version: 1.0 Subject: Re: UnicodeEncodeError when not running script from IDE From: Magnus Pettersson To: comp.lang.python@googlegroups.com Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Cc: "comp.lang.python" 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: , Message-ID: Lines: 61 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1360700325 news.xs4all.nl 6863 [2001:888:2000:d::a6]:34694 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:38780 I have tried now to take away printing to terminal and just keeping the wri= ting to a .txt file to disk (which is what the scripts purpose is): with open(filepath,"a") as f: for card in cardlist: f.write(card+"\n") The file it writes to exists and im just appending to it, but when i run th= e script trough eclipse, all is fine. When i run in terminal i get this err= or instead: File "K:\dev\python\webscraping\kanji_anki.py", line 69, in savefile f.write(card+"\n") UnicodeEncodeError: 'ascii' codec can't encode character u'\u898b' in posit= ion 3 2: ordinal not in range(128) On Tuesday, February 12, 2013 12:01:19 PM UTC+1, Andrew Berg wrote: > On 2013.02.12 04:43, Magnus Pettersson wrote: >=20 > > I am using Eclipse to write my python scripts and when i run them from = inside eclipse they work fine without errors.=20 >=20 > >=20 >=20 > > But almost in every script that handle some form of special characters = like swedish =E5=E4=F6 and chinese characters etc i get Unicode errors when= running the script externally with python.exe or pythonw.exe (but the scri= pts run completely fine from within Eclipse (standard pydev projects, pytho= n2.7). I have usually launched the script gui from wihin eclipse because of= this error but now i want to get the bottom of this so i dont have to open= eclipse everytime i want to run a script! >=20 > >=20 >=20 > > Here is the error i get now when running the script with python.exe: >=20 > > UnicodeEncodeError:'charmap' codec cant encode character u'\u898b' in p= osition 32: character maps to >=20 > >=20 >=20 > > what can i do to fix this? >=20 > >=20 >=20 > Since you didn't say what code actually does this, I'll turn to my >=20 > crystal ball. It says you are trying to print characters to a terminal >=20 > that doesn't support them. If that is the case, you could try changing >=20 > the code page (but only 3.3 supports cp65001, so that probably won't >=20 > help) or use replacement characters when printing. >=20 >=20 >=20 > --=20 >=20 > CPython 3.3.0 | Windows NT 6.2.9200.16461 / FreeBSD 9.1-RELEASE