Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

"run -i" no longer works after %reset in terminal #693

Closed
rabbitmcrabbit opened this Issue · 4 comments

4 participants

rabbitmcrabbit Min RK Thomas Kluyver Fernando Perez
rabbitmcrabbit

this appears to be a result of __name__ being lost:

/usr/local/lib/python2.6/dist-packages/IPython/core/interactiveshell.pyc in magic(self, arg_s, next_input)
   1892                 self._magic_locals = sys._getframe(1).f_locals
   1893             with self.builtin_trap:
-> 1894                 result = fn(magic_args)
   1895             # Ensure we're not keeping object references around:

   1896             self._magic_locals = {}

/usr/local/lib/python2.6/dist-packages/IPython/core/magic.pyc in magic_run(self, parameter_s, runner, file_finder)
   1587             # Run in user's interactive namespace

   1588             prog_ns = self.shell.user_ns
-> 1589             __name__save = self.shell.user_ns['__name__']
   1590             prog_ns['__name__'] = '__main__'
   1591             main_mod = self.shell.new_main_mod(prog_ns)

KeyError: '__name__'


In [1]: dir()
Out[1]: 
['In',
 'Out',
 '_',
 '__',
 '___',
 '__builtin__',
 '__builtins__',
 '__name__',
 '_dh',
 '_i',
 '_i1',
 '_ih',
 '_ii',
 '_iii',
 '_oh',
 '_sh',
 'exit',
 'get_ipython',
 'help',
 'quit']

In [2]: __name__
Out[2]: '__main__'

In [3]: %reset
Once deleted, variables cannot be recovered. Proceed (y/[n])?  y

In [4]: dir()
Out[4]: 
['In',
 'Out',
 '__builtin__',
 '__builtins__',
 '_dh',
 '_i',
 '_i4',
 '_ih',
 '_ii',
 '_iii',
 '_oh',
 '_sh',
 'exit',
 'get_ipython',
 'help',
 'quit']

In [5]: __name__
Out[5]: '__builtin__'
rabbitmcrabbit

oops -- github markup has chewed up the variable names here. they should be

__name__
rabbitmcrabbit

nope, i'm still not getting the hang of this yet...
__name__ is the problem variable above.

Min RK
Owner

Thanks for the catch - reset is definitely being too aggressive here.

When doing a big code paste, you can just wrap it in a <pre> tag, so it won't interpret anything as formatting.

Thomas Kluyver
Owner

I think this should be fixed in my big Usermod PR (#648): https://github.com/ipython/ipython/pull/648/files#L2R1103

Fernando Perez fperez closed this in a1e4911
Stefan van der Walt stefanv referenced this issue from a commit in stefanv/ipython
Thomas Kluyver takluyver Add test for gh-693 (%run -i after %reset). b26bf6a
Brian E. Granger ellisonbg referenced this issue from a commit
Commit has since been removed from the repository and is no longer available.
Fernando Perez fperez referenced this issue from a commit
Commit has since been removed from the repository and is no longer available.
matthew von rocketstein mattvonrocketstein referenced this issue from a commit in mattvonrocketstein/ipython
Thomas Kluyver takluyver Add test for gh-693 (%run -i after %reset). 95ad509
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.