<< pyrun | Python engine |
pyrunfile(filename) |
pyrunfile(filename input) |
outvars = pyrunfile(filename, outputs) |
outvars = pyrunfile(filename, outputs, pyName, pyValue, ...) |
a string scalar, character vector: filename .py to run.
a string scalar, character vector: filename .py to run with input arguments.
Input arguments name and value
string array: Python variable names.
One or more Nelson workspace variable names returned as valid Python types.
pyrunfile(filenam) function executes Python file.
In contrast to the pyrun function, variables generated in the Python workspace through the pyrunfile function do not persist. This means that subsequent calls to pyrunfile won't be able to access these variables.
The code outvars = pyrunfile(file, outputs, pyName1, pyValue2, ..., pyNameN, pyValueN) executes the code with one or more name-value pair arguments.
Known limitation:
The pyrun and pyrunfile functions lack support for classes containing local variables initialized by other local variables via methods. In such cases, it's advisable to create a module and access it instead.
pyrunfile_example_1.py
content = "hello Nelson"
print(content)
pyrunfile from Nelson
pyrunfile('pyrunfile_example_1.py')
pyrunfile_example_2.py
import sys
print('greetings from:')
for arg in sys.argv[0:]:
print(arg)
pyrunfile from Nelson with arguments
pyrunfile('pyrunfile_example_2.py "Hello" "world"')
pyrunfile_example_3.py
def minus(a,c):
b = a-c
return b
z = minus(x, y)
pyrunfile from Nelson with values from Nelson
pyrunfile('pyrunfile_example_3.py', 'x', 5, 'y', 3)
pyrun, pyenv, Python types supported.
Version | Description |
---|---|
1.4.0 | initial version |
Allan CORNET