def _get_globals(): """Return current Python interpreter globals namespace""" from __main__ import __dict__ as namespace shell = namespace.get('__ipythonshell__') if shell is not None and hasattr(shell, 'user_ns'): # IPython 0.13+ kernel return shell.user_ns else: # Python interpreter return namespace return namespace
def _get_globals(): """Return current Python/IPython interpreter globals namespace""" from __main__ import __dict__ as namespace if hasattr(__builtin__, '__IPYTHON__'): # IPython 0.10 shell = __builtin__.__IPYTHON__ else: # IPython 0.11+ shell = namespace.get('__ipythonshell__') if shell is not None and hasattr(shell, 'user_ns'): # IPython return shell.user_ns else: return namespace
def _get_interpreter_globals(): """Return current Python interpreter globals namespace""" if _get_globals_callback is not None: return _get_globals_callback() else: try: from __main__ import __dict__ as namespace except ImportError: try: # The import fails on IronPython import __main__ namespace = __main__.__dict__ except: namespace shell = namespace.get('__ipythonshell__') if shell is not None and hasattr(shell, 'user_ns'): # IPython 0.12+ kernel return shell.user_ns else: # Python interpreter return namespace