Python Forum
Embedded Python PyObject_CallObject function - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Embedded Python PyObject_CallObject function (/thread-22778.html)



Embedded Python PyObject_CallObject function - JRHeisey - Nov-27-2019

  • It appears that PyObject_CallObject() always returns an PyObject pointer event when the Python function does not explicitly return a value or object.
  • Assuming that the call is successful.
  • One example is a parameter setter function.

Can anyone explain what is being returned and how I may make use of it?


RE: Embedded Python PyObject_CallObject function - casevh - Nov-27-2019

A Python function always returns something. If the function returns via a bare return statement, it actually returns None. From the interactive prompt, return values of None are not shown.

>>> def f():
...   return
... 
>>> f()
>>> x=f()
>>> print(x)
None
Assuming you know the function has no specific return value, there isn't much use for the new reference to None. Since you have a new reference, you must decrement the reference count before discarding it.

casevh