hscriptExpression(expression_string)
→ float
, str
, or tuple
Given an expression string, this function evaluates it as though it was an HScript expression on a parameter. The return type depends on the expression.
Raises hou.OperationFailed if the expression is invalid or generates an error occur during evaluation.
>>> hou.hscriptExpression("$HIP") '/path/to/hip/directory' >>> hou.hscriptExpression("$F") 1.0 >>> hou.hscriptExpression('vector("[1, 2, 3]")') (1.0, 2.0, 3.0) >>> hou.hscriptExpression('matrix("[[1, 2][3, 4]]")') ((1.0, 2.0), (3.0, 4.0)) >>> hou.hscriptExpression("hello") 'hello' >>> hou.hscriptExpression("'hello'") 'hello' >>> hou.hscriptExpression("'hello' + ' world'") 'hello world' >>> hou.hscriptExpression('"$F"') '1' >>> hou.hscriptExpression("'$F'") '$F'
This function is somewhat similar to hou.expandString(), however, expandString will replace the portions of the string containing variables, leaving the rest of the string unchanged. If the variable is unknown, it will not do any expansion.
>>> hou.expandString("$HOME") '/home/me' >>> hou.expandString("HOME is $HOME") 'HOME is /home/me' >>> hou.hscriptExpression("HOME is $HOME") Traceback (most recent call last): File "<console>", line 1, in <module> File "/opt/hfs10.5/houdini/python2.5libs/hou.py", line 19331, in hscriptExpression return _hou.hscriptExpression(*args) OperationFailed: The attempted operation failed. Syntax error - extra tokens detected in expression >>> hou.expandString("$F") '1' >>> hou.expandString('"$F"') '"1"' >>> hou.hscriptExpression("$GARBAGE") Traceback (most recent call last): File "<console>", line 1, in <module> File "/opt/hfs10.5/houdini/python2.5libs/hou.py", line 19331, in hscriptExpression return _hou.hscriptExpression(*args) OperationFailed: The attempted operation failed. Undefined variable >>> hou.expandString("$GARBAGE") '$GARBAGE' >>> hou.hscript("echo -n $GARBAGE")[0] '' >>> hou.expandString("") '' >>> hou.hscriptExpression("") Traceback (most recent call last): File "<console>", line 1, in <module> File "/opt/hfs10.5/houdini/python2.5libs/hou.py", line 19331, in hscriptExpression return _hou.hscriptExpression(*args) OperationFailed: The attempted operation failed. Invalid expression
See also |