python - UnicodeEncodeError when using the compile function -



python - UnicodeEncodeError when using the compile function -

using python 3.2 in windows 7 getting next in idle:

>>compile('pass', r'c:\temp\工具\module1.py', 'exec') unicodeencodeerror: 'mbcs' codec can't encode characters in position 0--1: invalid character

can explain why compile statement tries convert unicode filename using mbcs? know sys.getfilesystemencoding returns 'mbcs' in windows, thought not used when unicode file names provided.

for example:

f = open(r'c:\temp\工具\module1.py')

works.

for more finish test save next in utf8 encoded file , run using standard python.exe version 3.2

# -*- coding: utf8 -*- fname = r'c:\temp\工具\module1.py' # have file named fname can comment out next 2 lines f = open(fname) print('ok') cmp = compile('pass', fname, 'exec') print(cmp)

output:

ok traceback (most recent phone 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

from python issue 10114, seems logic filenames used python should valid platform used. encoded using filesystem encoding used in c internals of python.

i agree shouldn't throw error on windows, because unicode filename valid. may wish file bug study python this. aware necessary changes might not trivial, because c code using filename has have if can't encoded.

python windows unicode python-3.x

Comments

Popular posts from this blog

How do I check if an insert was successful with MySQLdb in Python? -

delphi - blogger via idHTTP : error 400 bad request -

postgresql - ERROR: operator is not unique: unknown + unknown -