On Mon, 2011-08-08 at 09:05 -0700, SElsner wrote:
> Hello,
> 
> Please see this short script:
> 
> # -*- coding: utf-8 -*-
> a = "ä"
> print unicode(a)
> 
> It does work if not compile with pyinstaller. If compiled with:
> 
> pyinstaller.py scriptname.py
> 
> I get an error:
> 
> Traceback (most recent call last):
>   File "<string>", line 4, in <module>
> UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position
> 0: ordinal not in range(128)
> 
> Using latest trunk with python 2.6.6 32bit on windows xp pro 64bit

Your code above does not run in a standard Python installation:

$ cat foooo.py 
# -*- coding: utf-8 -*-
a = "ä"
print unicode(a)

$ python foooo.py 
Traceback (most recent call last):
  File "foooo.py", line 3, in <module>
    print unicode(a)
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 0: ordinal 
not in range(128)


My crystal ball says that it works for you because you have modified the
default Python encoding, maybe following an ill-advised blog post like
this:
http://blog.ianbicking.org/illusive-setdefaultencoding.html

Maybe you've put something in your site.py/sitecustomize.py. You
shouldn't do that, specifically because your code then becomes
not-interoperable with different Python installation (and thus with
PyInstaller).

The correct way to achieve what you want is to explicitly name the
encoding of your 8-bit strings during the decoding process, so either:

print unicode(a, "utf-8")

or

print a.decode("utf-8")
-- 
Giovanni Bajo   ::  [email protected]
Develer S.r.l.  ::  http://www.develer.com

My Blog: http://giovanni.bajo.it
Last post: The algorithms behind OTP tokens

Attachment: smime.p7s
Description: S/MIME cryptographic signature

Reply via email to