Tin mới
Defining Extension Types: Tutorial
Extending and Embedding the Python Interpreter
Finalization and De-allocation¶
This section aims to give a quick fly-by on the various type methods you can implement and what they do.
Finalization and De-allocation¶
This section aims to give a quick fly-by on the various type methods you can implement and what they do.
This section aims to give a quick fly-by on the various type methods you can implement and what they do.
This function is called when the reference count of the instance of your type is reduced to zero and the Python interpreter wants to reclaim it. If your type has memory to free or other clean-up to perform, you can put i
Finalization and De-allocation¶
This function is called when the reference count of the instance of your type is reduced to zero and the Python interpreter wants to reclaim it. If your type has memory to free or other clean-up to perform, you can put i
In Python, there are two ways to generate a textual representation of an object: the repr() function, and the str() function. (The print() function just calls str().) These handlers are both optional.
In Python, there are two ways to generate a textual representation of an object: the repr() function, and the str() function. (The print() function just calls str().) These handlers are both optional.
Most extension types only use simple attributes. So, what makes the attributes simple? There are only a couple of conditions that must be met:
Most extension types only use simple attributes. So, what makes the attributes simple? There are only a couple of conditions that must be met:
Most extension types only use simple attributes. So, what makes the attributes simple? There are only a couple of conditions that must be met:
The tp_richcompare handler is called when comparisons are needed. It is analogous to the rich comparison methods, like __lt__(), and also called by PyObject_RichCompare() and PyObject_RichCompareBool().
Python supports a variety of abstract ‘protocols;’ the specific interfaces provided to use these interfaces are documented in Abstract Objects Layer.
Python supports a variety of abstract ‘protocols;’ the specific interfaces provided to use these interfaces are documented in Abstract Objects Layer.
args is a tuple containing the arguments to the call. You can use PyArg_ParseTuple() to extract the arguments.
Python supports a variety of abstract ‘protocols;’ the specific interfaces provided to use these interfaces are documented in Abstract Objects Layer.
weakref: Support for weak references and weak dictionaries.
One of the goals of Python’s weak reference implementation is to allow any type to participate in the weak reference mechanism without incurring the overhead on performance-critical objects (such as numbers).