Creating a python object from C

M.-A. Lemburg mal at lemburg.com
Thu Sep 9 06:52:42 EDT 1999


Jacques wrote:
> 
> Any examples
> 
> i.e.
> 
> I have a class in python called One in module test
> 
> How would I instantiate this class One in C

First, get the pointer to the module 'test', then query its attribute
'One' and finally pass the object to e.g. PyObject_CallFunction().

Sorry, don't have time to elaborate. See the C API docs available
on python.org for details.

BTW, calling the class to instantiate it is exactly what you
are doing in Python too to create an instance. So there's nothing
special about it.

> -----Original Message-----
> From: M.-A. Lemburg [mailto:mal at lemburg.com]
> Sent: Thursday, September 09, 1999 11:31 AM
> To: Jacques Oosthuizen
> Cc: Python List @ Python.org
> Subject: Re: Creating a python object from C
> 
> Jacques Oosthuizen wrote:
> >
> > Is it possible to instantiate a python object from a C module.!!!!
> 
> Yes, all you have to do is call the Python class object with
> the constructor arguments, e.g. use PyObject_Call*(). It will
> then return an instance.
> 
> --
> Marc-Andre Lemburg
> ______________________________________________________________________
> Y2000:                                                   113 days left
> Business:                                      http://www.lemburg.com/
> Python Pages:                           http://www.lemburg.com/python/

-- 
Marc-Andre Lemburg
______________________________________________________________________
Y2000:                                                   113 days left
Business:                                      http://www.lemburg.com/
Python Pages:                           http://www.lemburg.com/python/





More information about the Python-list mailing list