give an extension type a __dict__?

Rainer Deyke root at rainerdeyke.com
Tue Feb 20 22:49:13 EST 2001


"Paul Miller" <paul at fxtech.com> wrote in message
news:3A92FCE5.9CD17BE5 at fxtech.com...
> 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:

You should realize that the name 'Point' within Python does not refer to a
type, but a function (type 'builtin_function_or_method').  You can easily
(or maybe not so easily) modify the extension module so that 'Point' is
instead an object that acts like a function but also has additional
properties, such as the ability to hold attributes.  This is totally
different from modifying the actual type 'Point'.


--
Rainer Deyke (root at rainerdeyke.com)
Shareware computer games           -           http://rainerdeyke.com
"In ihren Reihen zu stehen heisst unter Feinden zu kaempfen" - Abigor





More information about the Python-list mailing list