UnicodeEncodeError in compile
88888 Dihedral
dihedral88888 at googlemail.com
Tue Jan 10 05:53:55 EST 2012
Terry Reedy於 2012年1月10日星期二UTC+8下午4時08分40秒寫道:
> On 1/9/2012 11:24 PM, pyscr... at gmail.com wrote:
> > Using python 3.2 in Windows 7 I am getting the following:
> >
> >>> compile('pass', r'c:\temp\工具\module1.py', 'exec')
> > UnicodeEncodeError: 'mbcs' codec can't encode characters in position 0--1: invalid character
> >
> > Can anybody explain why the compile statement tries to convert the unicode filename using mbcs? I know that sys.getfilesystemencoding returns 'mbcs' in Windows, but I thought that this is not used when unicode file names are provided.
>
> I get the same error running 3.2.2 under IDLE but not when pasting into
> Command Prompt. However, Command Prompt may be cheating by replacing the
> Chinese chars with '??' upon pasting, so that Python never gets them --
> whereas they appear just fine in IDLE.
>
> --
> Terry Jan Reedy
Thank you about the trick.
Use some wildcat pattern to get the name.py compiled to pwc in some
directory with utf-8 encoded chars.
More information about the Python-list
mailing list