UnicodeEncodeError when not running script from IDE
steve+comp.lang.python at pearwood.info
Tue Feb 12 12:43:00 CET 2013
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
A comment: they are not "special" characters. They're merely not American.
> 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>
Please show the *complete* traceback, including the line of code that causes
> what can i do to fix this?
My guess is that you are trying to print a character which your terminal
cannot display. My terminal is set to use UTF-8, and so it can display it
py> c = u'\u898b'
(or at least it would display fine if the font used had a glyph for that
character). Why there are still terminals in the world that don't default
to UTF-8 is beyond me.
If I manually change the terminal's encoding to Western European ISO 8859-1,
I get some moji-bake:
I can't replicate the exception you give, so I assume it is specific to
More information about the Python-list