我正在使用带ctypes的win32函数。
我将所有声明放在一个文件(wrapper
)中,并在main
文件中使用它们。
为什么我得到的error
函数没有定义?
如果我把声明放在主文件中,一切都会正常工作。
两个文件都在同一目录中。你知道吗
包装器.py
from ctypes import *
from ctypes import wintypes
# Create ctypes wrapper for Win32 functions we need, with correct argument/return types
_CreateMutex = windll.kernel32.CreateMutexA
_CreateMutex.argtypes = [wintypes.LPCVOID, wintypes.BOOL, wintypes.LPCSTR]
_CreateMutex.restype = wintypes.HANDLE
主.py
import wrapper
_CreateMutex(...)
错误:
NameError: name '_CreateMutex' is not defined
有(至少)两种解决方案:
或者
没有太多细节(也许读https://docs.python.org/3.5/tutorial/modules.html?)你知道吗
将“wrapper”添加到当前名称空间中—仅此而已,因此name\u CreateMutex()不存在。你知道吗
当你导入时包装器.py那么您应该使用: `你知道吗
相关问题 更多 >
编程相关推荐