Using python 3.2 on Windows 7, I get 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 someone explain why the compilation operator is trying to convert the file name to unicode using mbcs? I know that sys.getfilesystemencoding returns "mbcs" on Windows, but I thought it was not used when Unicode file names were specified.
eg:
f = open(r'c:\temp\工具\module1.py')
work.
For a more complete test, save the following in a utf8 encoded file and run it using the standard version of python.exe 3.2
fname = r'c:\temp\工具\module1.py'
f = open(fname)
print('ok')
cmp = compile('pass', fname, 'exec')
print(cmp)
Conclusion:
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
source
share