[Tutor] Embedding a simple python module [C extensions]
Danny Yoo
dyoo@hkn.eecs.berkeley.edu
Fri, 12 Apr 2002 10:26:36 -0700 (PDT)
> In this example the class instance is initiated by the following:
>
> object = module.klass()
>
> but, what will be change if i want to initiate a class instance like the
> following:
>
> object = module.klass(x,y,z)
The example that you have calls the class constructor here:
###
> pargs = Py_BuildValue("()");
> pinst = PyEval_CallObject(pclass, pargs); /* call class() */
> Py_DECREF(pclass);
> Py_DECREF(pargs);
###
If you want to pass some objects like x, y, and z, we can build up that
pargs tuple to include those. If x, y, and z are already PyObjects, we
can do something like:
pargs = Py_BuildValue("(OOO)", x, y, z);
Hope this helps!