bundles / numpy 2.4.3 / numpy / lib / _utils_impl / safe_eval
function
numpy.lib._utils_impl:safe_eval
source: /numpy/lib/_utils_impl.py :583
Signature
def safe_eval ( source ) Summary
Protected string evaluation.
Extended Summary
Evaluate a string containing a Python literal expression without allowing the execution of arbitrary non-literal code.
Parameters
source: strThe string to evaluate.
Returns
obj: objectThe result of evaluating
source.
Raises
: SyntaxErrorIf the code has invalid Python syntax, or if it contains non-literal code.
Examples
np.safe_eval('1') np.safe_eval('[1, 2, 3]') np.safe_eval('{"foo": ("bar", 10.0)}')⚠
np.safe_eval('import os')
✗np.safe_eval('open("/home/user/.ssh/id_dsa").read()')
✗Aliases
-
numpy.lib._utils_impl.safe_eval