473,385 Members | 1,359 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

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
0 1570

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

by: Mike Hoegeman | last post by:
I'm in a situation where -- i have a PyObject * that is a instance of an object -- i need to access a subobject of that (PyObject *) that is described to me as a dotted string, e.g.: ...
by: Elie B. | last post by:
Hi, I'm new to Python. I'm trying to embbed Python in my Windows application having some success with redirecting the stdin/out to my windows application using: In my C++ code I use...
by: | last post by:
I'm a newbie in Python and Python/C API.. I have a simple question. I want to access python dictionary data type from C extension module. ---- spam.c ---- #include <Python.h> PyObject...
by: Kim | last post by:
Hi everyone, I'm writing a embeded python program, and I want to evaluate some expression by calling function: PyRun_SimpleString("print 'hello'") I don't want to output it to stdout but...
by: Travis Berg | last post by:
I'm running into a problem when trying to perform a callback to a Python function from a C extension. Specifically, the callback is being made by a pthread that seems to cause the problem. If I...
by: Hugh Macdonald | last post by:
I've got a pure python module that parses a certain type of file. It has a load() function that allows a callback function to be passed for getting progress information. In straight python, this...
by: Java and Swing | last post by:
I need to write an extension for a C function so that I can call it from python. C code (myapp.c) ====== typedef unsigned long MY_LONG; char *DoStuff(char *input, MY_LONG *x) { ... } so...
by: joeedh | last post by:
Hi I'm getting extremely odd behavior. First of all, why isn't PyEval_EvalCode documented anywhere? Anyway, I'm working on blender's python integration (it embeds python, as opposed to python...
by: squishywaffle | last post by:
Greetings, I'm trying to wrap a function in a C library as a compiled C Python module. Everything is going great, but I've hit a snag. There's a function in the form of this: First the...
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.