instance = Class(<whatever>)
...and then return the newly created instance.
Anyone know how to do this?
--
Bill Barrington
CNN Interactive - http://cnn.com
bill.ba...@cnn.com
404 827-5572
start here:
http://www.python.org/doc/current/api/object.html
and then look at the cPickle.c source code
(see find_class, Instance_New, load_inst, ...).
</F>
coming soon:
http://www.pythonware.com/people/fredrik/librarybook.htm
Thanks for pointing me in the right direction. The only bit of trouble I had was figuring out that I needed to set 'args' to NULL and use the keyword dictionary parameter instead in the call to PyInstance_New, i.e.
PyObject *data = Py_BuildValue("{s:s}", "<name>", "<value>");
PyObject *object = PyInstance_New(class_name, NULL, data);It works great! Thanks again.
Regards,
Bill
-- Bill Barrington CNN Interactive - http://cnn.com bill.ba...@cnn.com 404 827-5572
If you check out the code in Modules/newmodule.c, you can even
create an instance of a class without calling its constructor.
This can be very handy for having an instance returned from
a different class, which can't be instantiated by the Python
programmer.
--------------------------------------------
Adrian Eyre <mailto:a.e...@optichrome.com>
Optichrome Computer Solutions Ltd
Maybury Road, Woking, Surrey, GU21 5HX, UK
Tel: +44 1483 740 233 Fax: +44 1483 760 644
http://www.optichrome.com
--------------------------------------------
The trick is to get a reference to the class object and then
*call* it with your init parameters. It will then return an
instance just like in Python.
For code, see the examples Fredrik pointed you at.
Hope that helps,
--
Marc-Andre Lemburg
______________________________________________________________________
Y2000: 78 days left
Business: http://www.lemburg.com/
Python Pages: http://www.lemburg.com/python/