python - 属性错误 : module 'ctypes.wintypes' has no attribute 'create_unicode_buffer'

标签 python compiler-errors ctypes python-3.5

这是我的代码的一部分:

import os

def _get_appdata_path():
    import ctypes
    from ctypes import wintypes, windll
    CSIDL_APPDATA = 26
    _SHGetFolderPath = windll.shell32.SHGetFolderPathW
    _SHGetFolderPath.argtypes = [wintypes.HWND,
                                 ctypes.c_int,
                                 wintypes.HANDLE,
                                 wintypes.DWORD,
                                 wintypes.LPCWSTR]
    path_buf = wintypes.create_unicode_buffer(wintypes.MAX_PATH)
    result = _SHGetFolderPath(0, CSIDL_APPDATA, 0, 0, path_buf)
    return path_buf.value

但是当我调用 wintypes.create_unicode_buffer() 时,我得到了错误:

AttributeError: module 'ctypes.wintypes' has no attribute 'create_unicode_buffer'

我正在使用 Python 3.5.1。我能做什么?

最佳答案

使用 ctypes.create_unicode_buffer,它在 PY2 和 PY3 中都有效。由于使用 from ctypes import *,它只是在 PY2 的 wintypes 中意外出现。 :D

关于python - 属性错误 : module 'ctypes.wintypes' has no attribute 'create_unicode_buffer' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40084734/

相关文章:

python - PEP 8 和列表理解

python - 什么时候使用迭代器,什么时候使用生成器?

python - 将文件解密为流并将流读入 p​​andas(hdf 或 stata)

python - 从 csv 文件中提取日期范围并将其写入新文件,没有任何反应

c++ - 为什么前向声明不能修复循环依赖?

Linux 上 C 的编译错误

haskell - 如果我们可以禁用功能,错误消息会改善吗?

python - 使用 ctypes 将路径从 python 2 和 3 传递到 c++

python - 定义 c_char Python 的数组长度

python - 无法使用 ctypes.pythonapi 调整元组的大小