我从我的 python 脚本 (checkData.py) 创建了一个可执行文件
我正在尝试将包含语言环境字符的字符串数据从另一个 python 脚本传递给这个 exe 文件,如下所示:
...
dataPath = easygui.fileopenbox(msg, title)
p= subprocess.Popen(["checkData.exe", dataPath], stdout = subprocess.PIPE )
当我从调用者脚本打印时dataPath
,我可以看到语言环境字符。当我尝试打印传递给 exe 文件的字符串时出现错误。
...
parser = ArgumentParser()
parser.add_argument("directory", action="store")
args = parser.parse_args()
print(args.directory)
这是我的错误信息:
C:\script\build\exe.win32-3.2>checkSimTestData.exe
dataDirectoryPath= C:\samples\şample_test_data
Traceback (most recent call last):
File "c:\python32\lib\site-packages\cx_Freeze\initscripts\Console3.py",
line 27, in <module> exec(code, m.__dict__)
File "checkData.py",
line 56, in <module>
File "C:\Python\32-bit\3.2\lib\encodings\cp1254.py",
line 19, in encode
UnicodeEncodeError: 'charmap' codec can't encode character '\xfe'
in position 80: character maps to <undefined> –
当我运行以下命令时:
sys.stdout.encoding
我得到“cp1254”
请问你能帮帮我吗?