Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Re: "str object is not callable" error

Reply
Thread Tools

Re: "str object is not callable" error

 
 
Gabriel Genellina
Guest
Posts: n/a
 
      04-13-2009
En Wed, 08 Apr 2009 18:11:37 -0300, venkat sanaka <(E-Mail Removed)>
escribió:

> i was using python/c api to call a python function from c and I know the
> name of the function which i want to call.Is there any way to do that??
> This is the method i tried...
>
> for eg:This is the python function i wants to call.
> >>>def add(x):

> ... return x+10
>
>
> This is my code in C:
> PyObject *result = NULL;
> int arg;
> PyObject *arglist;
> arg = 123;
> my_callback = "add";
> arglist = Py_BuildValue("(i)", arg);
> result = PyObject_CallObject(my_callback, arglist);
> Py_DECREF(arglist);
> return result;
>
> I was getting a error like "str object is not callable".From the error i
> came to know that i was assigning "add" as a string which caused this
> error.Then how to make it a callable object??


This is what one would write in Python:

import some_module
some_module.add(123)

Do the same in C:

callback = PyObject_GetAttrString(some_module, "add");
if (!callback) ...error...
result = PyObject_CallFunction(callback, "i", arg);
Py_DECREF(callback);
return result;

--
Gabriel Genellina

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[compilation error] debugging this error message "Object() in java.lang.Object cannot be applied to" Gavin Java 3 03-28-2007 05:57 AM
Object creation - Do we really need to create a parent for a derieved object - can't the base object just point to an already created base object jon wayne C++ 9 09-22-2005 02:06 AM
Error:Object reference not set to an instance of an object. Suresh Kojhani ASP .Net 1 07-29-2004 12:10 PM
Error !Object reference not set to an instance of an object. !!! Help Parthiv Joshi ASP .Net 2 07-02-2004 10:28 AM
HELP! Error Loading ASPX : Object Reference not set to an instance object Pedro Correia ASP .Net 0 07-25-2003 10:42 AM



Advertisments