print values from Py_BuildValue

A

ashtonn

Hello,

How do i print values returned by Py_BuildValue in Linux?

PyObject *obj = Py_BuildValue("{s:i}", "Status", status);

I need to print the Status value here

-Thanks,
Ashton
 
?

=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=

How do i print values returned by Py_BuildValue in Linux?

PyObject *obj = Py_BuildValue("{s:i}", "Status", status);

I need to print the Status value here

I'm confused. You say you need to print the Status value here,
but then you also say you want to print the value returned
from Py_BuildValue, which is *not* the status value, but
a dictionary.

You also don't say whether you want to print this using
Python code or C code, so this gives a total of four interpretations
of your question:

1. Print status from C, on Linux:

printf("The status is %d\n", status);

2. Print status from Python:

print dict_returned_from_buildvalue['Status']

3. Print value returned from Py_BuildValue, from Python:

print dict_returned_from_buildvalue

4. Print value returned from Py_BuildValue, in C

PyObject_Print(obj, stdout, 0);

HTH,
Martin
 
J

John Machin

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,528
Members
45,000
Latest member
MurrayKeync

Latest Threads

Top