Writing class factories with the Python/C API?

Craig Ringer craig at postnewspapers.com.au
Sun Dec 5 07:40:32 EST 2004


Hi folks

I'm currently faced with the need to write a class factory in C using
the Python/C API. It's purpose is to automatically wrap C++ objects at
run-time and provide a Python object. Thanks to the magic of Qt's
meta-object system, getting the information required to wrap the C++
object is the easy bit.

What I'm not sure I can do is create 'built-in' Python classes at run
time. I don't need to create classes in response to calls from Python
code, only C code, but the newly created classes do need to be available
to Python code of course. The newly created classes will be fairly
simple subclasses of a more powerful parent, and all they really need to
do is implement a bunch of methods and 

So, before I throw myself too deeply into this task, does this sound
like something that's vaguely practical? All I'll really need to do is
add a bunch of methods on the generated subclasses, so I'm hoping so...

--
Craig Ringer




More information about the Python-list mailing list