Go to: Synopsis. Return value. MEL examples.
python
string [string...]
python is undoable, NOT queryable, and NOT editable.
This command executes Python scripts from MEL. The command receives strings containing a snippet of Python code. That code is executed and then the result in returned to MEL. If multiple strings are specified they will be joined together with newlines into a single multi-line script before being executed. Note that only single-line Python scripts will return a result due to a limitation in the Python interpreter. The return type from the Python code will be converted into a MEL type. Python integer, float, and string return values will be converted into the match MEL types. As well, if the Python code returns a list, the python command will try to determine if it could be converted into a MEL array. MEL arrays of ints, floats, and strings are supported. If none of these conversions are possible, then Python will return the string representation of the returned object.| string[] | The result of processing the input string by the Python interpreter. |
python( "import sys" );
// Call some python that will return a list of values. Note that we are
// calling the python command with a single python statement. We have to
// do that if we want to get a result back
//
string $version[] = python( "sys.version_info" );
// The result will be an array of strings because one of the elements will
// contain a string. Extract the major and minor parts of the version number
//
int $major = int( $version[0] );
int $minor = int( $version[1] );
// You can do multi-statement Python scripts, but there won't be a return value
python(
"import os",
"print os.environ[ 'MAYA_LOCATION' ]"
);