MCPcopy Create free account
hub / github.com/ipython/ipython / user_expressions

Method user_expressions

IPython/core/interactiveshell.py:2651–2676  ·  view source on GitHub ↗

Evaluate a dict of expressions in the user's namespace. Parameters ---------- expressions : dict A dict with string keys and string values. The expression values should be valid Python expressions, each of which will be evaluated in the user na

(self, expressions)

Source from the content-addressed store, hash-verified

2649 return value
2650
2651 def user_expressions(self, expressions):
2652 """Evaluate a dict of expressions in the user's namespace.
2653
2654 Parameters
2655 ----------
2656 expressions : dict
2657 A dict with string keys and string values. The expression values
2658 should be valid Python expressions, each of which will be evaluated
2659 in the user namespace.
2660
2661 Returns
2662 -------
2663 A dict, keyed like the input expressions dict, with the rich mime-typed
2664 display_data of each value.
2665 """
2666 out = {}
2667 user_ns = self.user_ns
2668 global_ns = self.user_global_ns
2669
2670 for key, expr in expressions.items():
2671 try:
2672 value = self._format_user_obj(eval(expr, global_ns, user_ns))
2673 except:
2674 value = self._user_obj_error()
2675 out[key] = value
2676 return out
2677
2678 #-------------------------------------------------------------------------
2679 # Things related to the running of code

Callers 2

test_user_variablesFunction · 0.80
test_user_expressionFunction · 0.80

Calls 2

_format_user_objMethod · 0.95
_user_obj_errorMethod · 0.95

Tested by 2

test_user_variablesFunction · 0.64
test_user_expressionFunction · 0.64