Id like to know how to perform the functionality of the ‘execfile’ Python command
but from C#. In this example:
var runtime = Python.CreateRuntime();
dynamic scope = Python.UseFile("body.py");
you specify the body file.
In the header of body.py, I specify the header:
execfile('header.py')
I would like to make that execfile from C#, how can I do that?
Note: Import does not work because i’m declaring variables dynamically inside
header.py scope. import would not import that variables because they do
not exist yet.
Thank you very much!
If you want different behaviour from the exec file you can easily create your own and do things like this (share scope) by creating the function in .NET and set this to the scope. This would also allow you to add additional functionality if you wish.
This seems to work:
Setting up the engine:
Then I create the function that can be used by scripts and set it on the scope
Now my Body.py looks like this:
And my Header.py Looks like this:
It is now able to use the same scope in the different scripts so you can share the variables.