print values from Py_BuildValue

John Machin sjmachin at lexicon.net
Thu Jul 7 17:46:35 EDT 2005


ashtonn at gmail.com wrote:
> Hello,
> 
> How do i print values returned by Py_BuildValue in Linux?

1. The same way as you would "in" any other operating system.
2. With difficulty.
3. If you must print something from C, print the C components (no 
difficulty).
4. If you are interested in checking what you have created, return the 
value to the Python caller, and print from there (no difficulty).
5. However if you have a debugging problem, read on ...

> 
> PyObject *obj = Py_BuildValue("{s:i}", "Status", status);
> 
> I need to print the Status value here

What is the 'Status' value?
'"Status"' and 'status' are C expressions which you should be able to 
print using printf.
Do you mean 'obj'?
Why do you think you need to print something here? Are you asking 
because you are getting a strange exception?
Have you tested the value returned by Py_BuildValue -- like this:
    /* the following line is written to clarify intent,
    not as an example of good coding style :-) */
    if (obj == NULL) goto free_resources_and_return_NULL;

Are you extending or embedding?
Is this your first attempt?
Have you considered using Pyrex? It does almost of the hard work for you.

HTH,
John



More information about the Python-list mailing list