pyrun
Run Python statements from Nelson.
📝Syntax
pyrun(code)
outvars = pyrun(code, outputs)
outvars = pyrun(code, outputs, pyName, pyValue)
📥Input Arguments
Parameter Description
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 Arguments
Parameter Description
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 thepyrun function remain persistent, allowing their usage in subsequentpyrun calls.

outvars = pyrun(code, outputs) Python variables specified in outputs are returned to Nelson.

The values of these variables are captured inoutvars.

outvars = pyrun(code, outputs, pyName, pyValue), thecode 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
pyrunfilepyenvPython types supported
🕔Version History
Version Description
1.3.0 initial version
1.4.0 Python code object allowed as first input argument
Edit this page on GitHub