Go to: Synopsis. Return value. MEL examples.

Synopsis

python string

python is undoable, NOT queryable, and NOT editable.

This command executes Python scripts from MEL. The command receives a string containing a snippet of Python code. That code is executed and then the result in returned to MEL.

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.

Return value

string[]The result of processing the input string by the Python interpreter.

MEL examples

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 mult-statement Python scripts, but there won't be a return
// value
python( "import os\nprint os.environ[ 'MAYA_LOCATION' ]" );