What is the point of defining new class as a struct in Python C API -
What is the point of defining new class as a struct in Python C API -
the docs python c api describes pattern of defining new type:
typedef struct { pyobject_head pyobject *first; /* first name */ pyobject *last; /* lastly name */ int number; } noddy; ...
then methods such init
added.
my question - point define custom fields in struct, why not define them in init
, in python, using pyobject_setattr function calls on self
?
struct fellow member access far more efficient dict lookups. struct fellow member access far more convenient in c. it's much easier thing->foo
pyobject_getattrstring(thing, "foo")
. using struct members allows store info isn't of python type. allows things can't implemented in terms of python types, or much less efficient in terms of python types. using struct members prevents every object needing own dict. of import result of dict doesn't have have infinite descending chain of dicts, improves space efficiency. this api existed before python-level class
statements , way statements things.
python c python-c-api
Comments
Post a Comment