I have a python function:
def log(text):
print text
saved in Callbacks.py file. Now I want to import it to c++ function and execute. This works fine:
py_fun = import("Callbacks");
py_fun.attr("log")(text);
But I would like to make log function part of a class:
class Logger:
def __init__(self):
self.last_read = -1
def log(self, text):
print text
How can I import it to C++ and create an instance of Logger?
Exactly the way you'd think:
py::object mod = py::import("Callbacks");
py::object logger = mod.attr("Logger")();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With