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)
| 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 |
no test coverage detected