我使用的是Python2.5&下面的代码产生2个错误。 有人能帮我吗?你知道吗
class EXCEPTION_RECORD(Structure):
_fields_ = [
("ExceptionCode", DWORD),
("ExceptionFlags", DWORD),
("ExceptionRecord", POINTER(EXCEPTION_RECORD)),
("ExceptionAddress", LPVOID),
("NumberParameters", DWORD),
("ExceptionInformation", ULONG_PTR * EXCEPTION_MAXIMUM_PARAMETERS)]
Python错误:
Traceback (most recent call last):
File "E:\Python25\my_debugger_defines.py", line 70, in <module>
class EXCEPTION_RECORD(Structure):
File "E:\Python25\my_debugger_defines.py", line 74, in EXCEPTION_RECORD
("ExceptionRecord", POINTER(EXCEPTION_RECORD)),
NameError: name 'EXCEPTION_RECORD' is not defined
Microsoft文档:
The EXCEPTION_RECORD structure describes an exception.
typedef struct _EXCEPTION_RECORD { // exr
DWORD ExceptionCode;
DWORD ExceptionFlags;
struct _EXCEPTION_RECORD *ExceptionRecord;
PVOID ExceptionAddress;
DWORD NumberParameters;
DWORD ExceptionInformation[EXCEPTION_MAXIMUM_PARAMETERS];
} EXCEPTION_RECORD;
提前谢谢
显然,在定义类时不能引用类类型,例如:
但是,您可以通过执行以下操作来解决此问题:
我将重新编写您的代码,如下所示:
看起来你做了一个
from ctypes import *
(糟糕的做法,因为人们只能猜测像DWORD
这样的标识符到底是从哪里来的!-)但错过了ctypes.Structure's docs中一段关键的短文:因此,只需将这部分文档应用到您的代码中,您就需要将代码更改为:
类可以在
__new__
或__init__
方法中引用自身。你知道吗或:
或者,如果你真的想得到幻想,你可以使用
__metaclass__
。你知道吗相关问题 更多 >
编程相关推荐