3.1 MEL command: py


py <string>

The py command executes Python source code given as a string. The command is somewhat equivalent to the builtin MEL command eval.

The string may either contain a single expression, a single statement or a sequence of statements (separated by semicolons or newlines) and is always executed inside the same namespace, so changes to the environment are visible in subsequent calls:

py "a=5";
py "print a";

The namespace is shared by the py and the pySource command, so you can call Python functions stored in a file by first executing the file and then calling the functions:

pySource myscript;  // execute the file myscript.py which defines a function spam()
py "spam()";    // invoke the Python function spam() and return its result

Return value:

If an expression was passed the result of the expression is returned.