MCPcopy Index your code
hub / github.com/ipython/ipython / push

Method push

IPython/core/interactiveshell.py:1590–1636  ·  view source on GitHub ↗

Inject a group of variables into the IPython user namespace. Parameters ---------- variables : dict, str or list/tuple of str The variables to inject into the user's namespace. If a dict, a simple update is done. If a str, the string is assumed to h

(self, variables, interactive=True)

Source from the content-addressed store, hash-verified

1588 del ns[var]
1589
1590 def push(self, variables, interactive=True):
1591 """Inject a group of variables into the IPython user namespace.
1592
1593 Parameters
1594 ----------
1595 variables : dict, str or list/tuple of str
1596 The variables to inject into the user's namespace. If a dict, a
1597 simple update is done. If a str, the string is assumed to have
1598 variable names separated by spaces. A list/tuple of str can also
1599 be used to give the variable names. If just the variable names are
1600 give (list/tuple/str) then the variable values looked up in the
1601 callers frame.
1602 interactive : bool
1603 If True (default), the variables will be listed with the ``who``
1604 magic.
1605 """
1606 vdict = None
1607
1608 # We need a dict of name/value pairs to do namespace updates.
1609 if isinstance(variables, dict):
1610 vdict = variables
1611 elif isinstance(variables, (str, list, tuple)):
1612 if isinstance(variables, str):
1613 vlist = variables.split()
1614 else:
1615 vlist = list(variables)
1616 vdict = {}
1617 cf = sys._getframe(1)
1618 for name in vlist:
1619 try:
1620 vdict[name] = eval(name, cf.f_globals, cf.f_locals)
1621 except:
1622 print('Could not get variable %s from %s' %
1623 (name,cf.f_code.co_name))
1624 else:
1625 raise ValueError('variables must be a dict/str/list/tuple')
1626
1627 # Propagate variables to user namespace
1628 self.user_ns.update(vdict)
1629
1630 # And configure interactive visibility
1631 user_ns_hidden = self.user_ns_hidden
1632 if interactive:
1633 for name in vdict:
1634 user_ns_hidden.pop(name, None)
1635 else:
1636 user_ns_hidden.update(vdict)
1637
1638 def drop_by_id(self, variables):
1639 """Remove a dict of variables from the user namespace, if they are the

Callers 2

store_inputsMethod · 0.45
update_user_nsMethod · 0.45

Calls 2

popMethod · 0.80
updateMethod · 0.45

Tested by

no test coverage detected