【发布时间】:2016-07-13 16:06:41
【问题描述】:
我有一个dll 和一个c 头文件.h。有一些函数接受cenum,例如;
enum Type
{
typeA,
typeB
};
还有一个函数
bool printType(Type type );
现在我想从 python 脚本中使用dll 的这个函数。我已经导入了库。这是成功的。我可以访问其他功能并且它可以工作。所以有一个像我上面给出的例子一样的函数,它以Enum 作为参数。
查看此处的其他帖子和互联网上的其他内容后,我尝试了什么;
# -*- coding: utf-8 -*-
from ctypes import *
from enum import IntEnum
class CtypesEnum(IntEnum):
@classmethod
def from_param(cls, obj):
return int(obj)
class Type(CtypesEnum):
typeA = 0
typeB = 1
我是这样使用的。
setEnumtype = self.printType
setEnumtype.argtypes = [Type]
setEnumVale.restype = c.c_int
result = self.printType(setEnumtype.typeA)
解释器说,它知道IntEnum。我已经通过 pip 安装了enum。
还有其他直接的方法吗?
追溯:
from enum import IntEnum
ImportError: cannot Import Name IntEnum
【问题讨论】:
-
请发布 exact 回溯(即复制并粘贴文本)
-
我已经发布了原始回溯。