Python win32创建文件使用UniCode Ch

2024-04-27 05:06:36 发布

您现在位置:Python中文网/ 问答频道 /正文

尝试使用win32访问具有俄语unicode字符的文件时文件.CreateFile(),我得到:

Traceback (most recent call last):
  File "test-utf8.py", line 36, in <module>
    None )
pywintypes.error: (123, 'CreateFile', 'The filename, directory name, or volume l
abel syntax is incorrect.')

这是密码。使用Python I。我验证可以用常规Python“open”打开它:

^{pr2}$

Tags: 文件pytestmostlineunicodeutf8call
1条回答
网友
1楼 · 发布于 2024-04-27 05:06:36

解决方案是使用CreateFileW而不是CreateFilefileH = win32file.CreateFileW

具有讽刺意味的是,documentation for CreateFile表示它支持PyUnicode字符串,但底层Windows函数不支持,除非使用CreateFileW。CreateFileW支持unicode的宽字符。在

感谢这篇讨论CreateFile的C版本的帖子:How do I open a file named ?.txt with CreateFile() API function?

相关问题 更多 >