python ctypes 问题
fromctypesimport*msvcrt=CDLL("msvcrt.dll")上面两句话,命令行里面打进去,正确,而在.py文件里面编译就报错:NameError:...
from ctypes import *
msvcrt = CDLL("msvcrt.dll")
上面两句话,命令行里面打进去,正确,而在 .py 文件里面编译就报错:
NameError: name 'CDLL' is not defined
为什么? 展开
msvcrt = CDLL("msvcrt.dll")
上面两句话,命令行里面打进去,正确,而在 .py 文件里面编译就报错:
NameError: name 'CDLL' is not defined
为什么? 展开
1个回答
展开全部
我在交互式环境下使用没问题,你查一下环境吧。另外,库名可以不加后缀名,因为linux下可能是so后缀的,加了也没关系。
C:\Users\s>python
Python 2.7.3 (default, Apr 10 2012, 23:31:26) [MSC v.1500 32 bit (Intel)] on win
32
Type "help", "copyright", "credits" or "license" for more information.
>>> from ctypes import *
>>> dir(CDLL)
['__class__', '__delattr__', '__dict__', '__doc__', '__format__', '__getattr__',
'__getattribute__', '__getitem__', '__hash__', '__init__', '__module__', '__new
__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__
str__', '__subclasshook__', '__weakref__', '_func_flags_', '_func_restype_']
>>> dll=CDLL("msvcrt")
>>> dll
<CDLL 'msvcrt', handle 75b30000 at 2624570>
>>> dll=CDLL("msvcrt.dll")
>>> dll
<CDLL 'msvcrt.dll', handle 75b30000 at 2608ed0>
C:\Users\s>python
Python 2.7.3 (default, Apr 10 2012, 23:31:26) [MSC v.1500 32 bit (Intel)] on win
32
Type "help", "copyright", "credits" or "license" for more information.
>>> from ctypes import *
>>> dir(CDLL)
['__class__', '__delattr__', '__dict__', '__doc__', '__format__', '__getattr__',
'__getattribute__', '__getitem__', '__hash__', '__init__', '__module__', '__new
__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__
str__', '__subclasshook__', '__weakref__', '_func_flags_', '_func_restype_']
>>> dll=CDLL("msvcrt")
>>> dll
<CDLL 'msvcrt', handle 75b30000 at 2624570>
>>> dll=CDLL("msvcrt.dll")
>>> dll
<CDLL 'msvcrt.dll', handle 75b30000 at 2608ed0>
追问
谢谢,我在交互式下也没问题,在 .py 下有问题,交互式和编译 py 文件环境配置有什么不一样?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询