2016-07-13 7 views
-1

dllcというヘッダーファイル.hがあります。例えば、cenumを受け入れる機能があります。ctypes pythonで引数としてenumを渡すには?

enum Type 
{ 
    typeA, 
    typeB 
}; 

と機能

bool printType(Type type); 

今私はPythonスクリプトからdllのこの機能を使用します。私は図書館を輸入しました。それは成功です。私は他の機能にアクセスでき、機能します。したがって、上記の例のように1つの関数があり、パラメータとして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をインストールしました。

これを行うもう1つの方法はありますか?

トレースバック:

from enum import IntEnum 
ImportError: cannot Import Name IntEnum 
+0

*正確なトレースバックを投稿してください(つまり、テキストをコピーして貼り付けてください) –

+0

私は元のトレースバックを掲載しました。 –

答えて

1

あなたがthe enum docs on pipを読めば、あなたはわかります

Python 3 now has in its standard library an enum implementation (also available for older Python versions as the third-party flufl.enum distribution) that supersedes this library.

は、あなたが実際にenum34をしたいです。

+0

attributeError:Instancmethodオブジェクトに型がない 'argtypes' –

+0

@ GulluButtこのエラーが発生しているコードで質問を更新したい場合があります –

関連する問題