creating an object in embedded python

Brian Quinlan brian at sweetapp.com
Wed May 14 18:46:56 EDT 2003


> // if PyErr_Occurred, print backtrace
> retval = PyObject_CallMethod( instance, "init", "i",
> fooarg );
> // if PyErr_Occurred, print backtrace
> 
> In master.py, it reads:
> class master:
>   def init( arg ):
>     etc...

You forgot the "self" argument i.e.

class master
    def init(self, arg):
        ....

> The error Im getting is:
> TypeError: init() takes exactly 1 argument (2 given)
> 
> Im sure this is something simple, Im just having a
> hard time groking the API docs to make them useful.

How well do you understand the Python programming language? I think that
understanding the language will help you a lot in understanding the API
documentation.

> For example, what is the difference between
> *callable_object in PyObject_CallObject() and
> *callable in PyObject_CallFunction()?

PyObject_CallObject - 
	requires you to create an argument tuple 
	and keyword dictionary yourself

PyObject_CallFunction -
	a convenience version of PyObject_CallObject
      that will build the argument tuple for you
      based on a format string and arguments


> What is the difference in there return values? 

None.

Cheers,
Brian






More information about the Python-list mailing list