print values from Py_BuildValue

2005-07-07 Thread [EMAIL PROTECTED]
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

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: print values from Py_BuildValue

2005-07-07 Thread Martin v. Löwis
[EMAIL PROTECTED] wrote:
 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
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: print values from Py_BuildValue

2005-07-07 Thread John Machin
[EMAIL PROTECTED] 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
-- 
http://mail.python.org/mailman/listinfo/python-list