UnicodeEncodeError when not running script from IDE

Magnus Pettersson magpettersson at gmail.com
Tue Feb 12 13:34:29 CET 2013


Ahh so its the actual printing that makes it error out outside of eclipse because its a different terminal that its printing to. Its the default DOS terminal in windows that runs then i run the script with python.exe and i guess its the same when i run with pythonw.exe just that the terminal window is not opened up, only the pyqt gui in this case.

I will try to fix it now when i know what it is :)

I never thought about the terminal, last time i had the same problem i just were playing around for hours with unicode encode and decode and all that not-so-fun stuff :)

Andrew Berg: Thanks, your crystal ball seems to be right :P

On Tuesday, February 12, 2013 12:43:00 PM UTC+1, Steven D'Aprano wrote:
> 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
> 
> the exception.
> 
> 
> 
>  
> 
> > 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
> 
> fine:
> 
> 
> 
> py> c = u'\u898b'
> 
> py> print(c)
> 
>> 
> 
> 
> 
> 
> (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:
> 
> 
> 
> py> print(c)
> 
> è¦
> 
> 
> 
> 
> 
> I can't replicate the exception you give, so I assume it is specific to
> 
> Windows.
> 
> 
> 
> 
> 
> 
> 
> 
> 
> -- 
> 
> Steven




More information about the Python-list mailing list