467,074 Members | 906 Online
Bytes | Developer Community
Ask Question

Home New Posts Topics Members FAQ

Post your question to a community of 467,074 developers. It's quick & easy.

PyObject_GetAttrString failing when getting a function pointerfr om PyObject* returned by Py_CompileString


My following code is failing with an error of "isSizeSmall not function or callable"

char szExpr[2048];
sprintf(szExpr,"def isSizeSmall(size,vol,ADV,prod):\n if ( (size < 1000) & (vol < (0.001 * ADV)) & (prod==\"Stock\")): return 100\n else: return 11\n\n\n");

PyObject* pyco = Py_CompileString(szExpr,"<stdin>", Py_file_input);

// Get a pointer to this function
char funcname[56];

PyObject* func = PyObject_GetAttrString(pyco,funcname);
if(!func || !PyCallable_Check(func))
printf("%s not function or callable\n");

In above case, Py_CompileString parses & compiles the code successfully.

Can we not use the "PyObject*" returned by Py_CompileString as input to PyObject_GetAttrString?
What could be wrong?

I want to use this function pointer returned by PyObject_GetAttrString as input to PyObject_CallObject.
Can I use the "PyObject*" returned by Py_CompileString directly as is in call to PyObject_CallObject?

Please help.

Thanks and Regards,

================================================== ============================
Please access the attached hyperlink for an important electronic communications disclaimer:

================================================== ============================

Nov 20 '07 #1
  • viewed: 1257

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Elie B. | last post: by
3 posts views Thread by Travis Berg | last post: by
3 posts views Thread by Hugh Macdonald | last post: by
10 posts views Thread by Java and Swing | last post: by
14 posts views Thread by squishywaffle@gmail.com | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.