Do python support pointers

Martin von Loewis loewis at
Thu May 24 18:27:46 CEST 2001

"Sameer Kshatriya" <sameerk at> writes:

> I have a problem is accessing a pointer variable.I have a dll, that
> iam loading in Python,one of its exported function returns a pointer
> to an interface using which iam suppose to call certain
> functions. Now iam not able to make call to functions using the
> pointer returned by the exported finction. How can i do this.

You need to create a Python wrapper object for the pointer. Suppose
the function returning the point is "foo", and the interface
operations are "bar" and "foobar". Then you'd do

PyObject *foo(...){
 return IWrapper_New(pointervalue);

IWrapper_bar(IWrapper* wr, PyObject*args){
  ... get args ...
  res = wr->wrapped_interface->bar(arguments);
  ... return result

IWrapper_foobar(IWrapper* wr, PyObject*args){
  ... get args ...
  res = wr->wrapped_interface->foobar(arguments);
  ... return result

>From Python, you'd then do

interface = args)

Please see the xxmodule.c source for an example of creating new types
in Python. If you need to create many different wrapper objects, you
may consider using SWIG.


More information about the Python-list mailing list