pyrun
Run Python statements from Nelson.
Syntax
- pyrun(code)
- outvars = pyrun(code, outputs)
- outvars = pyrun(code, outputs, pyName, pyValue)
Input argument
- code - a string scalar, string array, character vector, character array or python code object.
- pyName, pyValue - Input arguments name and value
- outputs - string array: Python variable names.
Output argument
- outvars - One or more Nelson workspace variable names returned as valid Python types.
Description
pyrun(code) function executes Python statements present in the code string within the Python interpreter.
Variables generated by the pyrun function remain persistent, allowing their usage in subsequent pyrun calls.
outvars = pyrun(code, outputs) Python variables specified in outputs are returned to Nelson.
The values of these variables are captured in outvars.
outvars = pyrun(code, outputs, pyName, pyValue), the code is executed with assigned input and output variable names using Nelson data passed through one or more name-value arguments.
Examples
pyrun('a = b * c', 'b', 5, 'c', 10)
r = pyrun('d = a + c', 'd')
pyrun(["a = 3","print(a)"])
[R1, R2] = pyrun("a=b*c",["a","b"], 'b', 5, 'c', 10)
Python code object representing a script generated through the built-in compile function in Python
PYCODE = pyrun('X = compile(''Y = 3'', ''test'', ''exec'')', 'X')
y = pyrun(PYCODE, 'Y')
See also
pyrunfile, pyenv, Python types supported.
History
Version | Description |
---|---|
1.3.0 | initial version |
1.4.0 | Python code object allowed as first input argument |
Author
Allan CORNET