give an extension type a __dict__?

Paul Miller paul at fxtech.com
Tue Feb 20 18:25:25 EST 2001


Is it possible to give an extension type a __dict__ to store
type-specific constants? Assume we create a Point object in C:

PyTypeObject point_type_info = 
{
	PyObject_HEAD_INIT(&PyType_Type)
	0,					// ob_size
	"Point",				// tp_name
	sizeof(PointType),			// tp_basicsize
	0,					// tp_itemsize

	etc...

In Python, I can create one of these:

	from point import Point
	p = Point()

But since my Point type *acts* like I class, I'd like to scope some
constants into its namespace, so I can do this:

	p = Point.ZERO

I realize I can put constants at the module scope in the module's
dictionary, but if I have many extension types, the global namespace
would be polluted.

Is this even possible?



More information about the Python-list mailing list