开发者

Trying to build a Python class in a C extension that can be instantiated from a Python module

开发者 https://www.devze.com 2023-03-31 00:22 出处:网络
I\'m trying to build an exception class that I can use both in a C extension and the Python modules that import the extension.I\'m using the PyErr_NewException to create the class as a superclass of t

I'm trying to build an exception class that I can use both in a C extension and the Python modules that import the extension. I'm using the PyErr_NewException to create the class as a superclass of the Exception class, but I can't figure out how to create an __init__ constructor for the class. I assume that is the best way to populate the class with t开发者_JS百科he attributes I need.


You should pass a dict as the third argument to PyErr_NewException. The dict should have an __init__ key bound to your initializer function.

0

精彩评论

暂无评论...
验证码 换一张
取 消