[IPython-user] ip.IP.magic_reset() confirmation

Martin Spacek ipython at mspacek.mm.st
Wed Jun 7 01:51:17 CDT 2006


Out of habit from Matlab, I have a function c() declared on IPython 
startup that lets me quickly clear the workspace. After importing:

import IPython
ip = IPython.ipapi.get()

it calls ip.IP.magic_reset(), but that always comes up with the warning 
"Once deleted, variables cannot be recovered. Proceed (y/n)?". I'd 
previously commented out this code in Magic.py, but I'm wondering if the 
nag could be made optional with a confirmation argument, maybe like this:

def magic_reset(self, parameter_s='', confirm=True):
     """Resets the namespace by removing all names defined by the user.

     Input/Output history are left around in case you need them."""

     if confirm:
         ans = raw_input(
           "Once deleted, variables cannot be recovered. Proceed (y/n)?")
         if not ans.lower() == 'y':
             print 'Nothing done.'
     user_ns = self.shell.user_ns
     for i in self.magic_who_ls():



More information about the IPython-user mailing list