-
Hello Is there a way to call a function passing the scope like I can do with py::exec? I'm doing it that way but I can't access the variable in the same scope of the function: myfile.py local_var = "test"
def my_func():
print(local_var) myfile.cpp auto local = py::dict();
auto globals = py::globals();
py::eval_file("myfile.py", globals, local);
py::object func = local["my_func"];
func(); And it results in the following message: |
Beta Was this translation helpful? Give feedback.
Answered by
danimasa
Nov 10, 2021
Replies: 1 comment
-
I find a way to read the local variables from inside the function. What I did was update the globals before running the function: auto local = py::dict();
auto globals = py::globals();
py::eval_file("myfile.py", globals, local);
globals.attr("update")(locals);
py::object func = local["my_func"];
func(); |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
danimasa
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I find a way to read the local variables from inside the function. What I did was update the globals before running the function: