【问题标题】:Using windll in ctypes on Windows 7 (64bit)在 Windows 7(64 位)上的 ctypes 中使用 windll
【发布时间】:2015-03-07 21:25:29
【问题描述】:

想问问有没有人和我一样的问题,有没有解决办法。

当我在安装 Windows 7(64 位)之前使用 Windows XP(32 位)时,我在 Python 2.7.8 中使用了以下程序,没有任何错误:

from ctypes import *
kernel = windll.kernel32
...

当我在当前版本的操作系统上运行此序列时,出现错误:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'windll' is not defined

有人能知道这个错误的根本原因在哪里以及如何解决这个问题吗?

【问题讨论】:

  • only import ctypes; print ctypes; print ctypes.windll 显示什么?
  • &gt;&gt;&gt; import ctypes 工作正常(没有错误)&gt;&gt;&gt; print ctypes &lt;module 'ctypes' from '/usr/lib/python2.7/ctypes/__init__.pyc'&gt; 也似乎工作正常&gt;&gt;&gt; print ctypes.windll Traceback (most recent call last): File "&lt;stdin&gt;", line 1, in &lt;module&gt; AttributeError: 'module' object has no attribute 'windll'
  • 抱歉,我的意思是只有这 3 行的脚本,而不是单独的每一行 -- 包含这 3 行的脚本会显示什么?
  • 出现如下错误:➤ python test_ctypes.py &lt;module 'ctypes' from '/usr/lib/python2.7/ctypes/__init__.pyc'&gt; Traceback (most recent call last): File "test_ctypes.py", line 4, in &lt;module&gt; print ctypes.windll AttributeError: 'module' object has no attribute 'windll'
  • 我尝试在 cmd.exe 下运行它 - 没有任何问题。看来根本原因在mobaxterm。

标签: python python-2.7 ctypes


【解决方案1】:

在 cmets 中描述的短脚本(由 jedwards 提出)在 mobaxterm 终端下运行时出现错误消息。在 cmd.exe 控制台中运行脚本时,不会出现任何错误。

谢谢大家,提醒...

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-09-05
    • 2011-11-25
    • 2023-03-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-03-10
    • 1970-01-01
    相关资源
    最近更新 更多