pass bool values to the Python function in embedded python 3.0

B

BigHand

Guys, How do I transfer the parameters ?
in python code:
traceback.format_exception(exc_type, exc_val, exc_tb, 2, True)

in C++ code:
obFunc_format_exception = PyObject_GetAttrString(modTB,
"format_exception");
tbArgs = Py_BuildValue("OOOii", exc_type, exc_value, exc_tb, 2, 1);
tbResultList = PyObject_CallObject(obFunc_format_exception , tbArgs);

how do I pass True to the Python function in the C++ code?
 
B

BigHand

Guys, How do I transfer the parameters ?
in python code:
traceback.format_exception(exc_type, exc_val, exc_tb, 2, True)

in C++ code:
obFunc_format_exception = PyObject_GetAttrString(modTB,
"format_exception");
tbArgs = Py_BuildValue("OOOii", exc_type, exc_value, exc_tb, 2, 1);
tbResultList = PyObject_CallObject(obFunc_format_exception , tbArgs);

how do I pass True to the Python function in the C++ code?
build the python object
tbArgs = Py_BuildValue("OOOOO", exc_type, exc_value, exc_tb, Py_None,
Py_True);
tbResultList = PyObject_CallObject(obFunc_format_exception , tbArgs);
but I can't get the format_exception called successfully.
could anyone help me ?
 
G

Gabriel Genellina

how do I pass True to the Python function in the C++ code?

(I've already suggested using PyErr_Print/PyTraceback_Print instead)

See the section "Boolean Objects" in the C API Reference:

"PyObject* Py_True
The Python True object. This object has no methods. It needs to be treated
just like any other object with respect to reference counts."
 
B

BigHand

(I've already suggested using PyErr_Print/PyTraceback_Print instead)

See the section "Boolean Objects" in the C API Reference:

"PyObject* Py_True
The Python True object. This object has no methods. It needs to be treated  
just like any other object with respect to reference counts."

tbArgs = Py_BuildValue("OOOOO", exc_type, exc_value, exc_tb,
Py_None,
Py_True);
tbResultList = PyObject_CallObject(obFunc_format_exception , tbArgs);

should increase the ref count of Py_True first?
this can't call the python function format_exception successfully
either.

B.R.
BH
 

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

Forum statistics

Threads
473,767
Messages
2,569,572
Members
45,045
Latest member
DRCM

Latest Threads

Top