I have a wrapper class as in the example below, written in Python.
class Foo:
def __init__(self, bar=None):
if bar:
self._bar = bar
else:
self._bar = CreateBarObject("value")
I create an instance via the Python C API
// c++ pseudo code for convenience
auto obj = PyObject_CallObject(Foo)
auto bar = CreateBarObject("another_value");
PyObject_SetAttrString(obj, "_bar", bar)
As you can see from the code, Foo.__init__
will be called when an instance gets created which creates a new bar
object. But I would like to bypass this "heavy" operation. So any safe way to create an instance of Foo so I can set self._bar
via the Python C API? Any ideas?