Using python 3.2 in Windows 7 I am getting the following in IDLE:
>>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.
f = open(r'c:\temp\工具\module1.py')
For a more complete test save the following in a utf8 encoded file and run it using the standard python.exe version 3.2
# -*- coding: utf8 -*- fname = r'c:\temp\工具\module1.py' # I do have the a file named fname but you can comment out the following two lines f = open(fname) print('ok') cmp = compile('pass', fname, 'exec') print(cmp)
ok Traceback (most recent call last): File "module8.py", line 6, in <module> cmp = compile('pass', fname, 'exec') UnicodeEncodeError: 'mbcs' codec can't encode characters in position 0--1: inval id character