UnicodeEncodeError when not running script from IDE
Magnus Pettersson
magpettersson at gmail.com
Tue Feb 12 09:24:21 EST 2013
I have tried now to take away printing to terminal and just keeping the writing 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 the script trough eclipse, all is fine. When i run in terminal i get this error 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 position 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:
>
> > I am using Eclipse to write my python scripts and when i run them from inside eclipse they work fine without errors.
>
> >
>
> > But almost in every script that handle some form of special characters like swedish åäö and chinese characters etc i get Unicode errors when running the script externally with python.exe or pythonw.exe (but the scripts run completely fine from within Eclipse (standard pydev projects, python2.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!
>
> >
>
> > Here is the error i get now when running the script with python.exe:
>
> > UnicodeEncodeError:'charmap' codec cant encode character u'\u898b' in position 32: character maps to <undefined>
>
> >
>
> > what can i do to fix this?
>
> >
>
> Since you didn't say what code actually does this, I'll turn to my
>
> crystal ball. It says you are trying to print characters to a terminal
>
> that doesn't support them. If that is the case, you could try changing
>
> the code page (but only 3.3 supports cp65001, so that probably won't
>
> help) or use replacement characters when printing.
>
>
>
> --
>
> CPython 3.3.0 | Windows NT 6.2.9200.16461 / FreeBSD 9.1-RELEASE
More information about the Python-list
mailing list