How to clear variables in ipython?

Sometimes I restart the script inside the same ipython session and I get nasty surprises when the variables have not been cleared. How to clear all variables? And is it possible to force it somehow every time I call the magic command% run?

thank

+79
python memory ipython
Apr 08 '14 at 10:24
source share
5 answers

%reset seems to clear certain variables.

+118
Apr 08 '14 at 10:27
source share

To delete a single variable:

 reset_selective name_variable 

may be helpful!

Additional information about a particular type of behavior:

 reset? 
+36
Nov 13 '14 at 9:48
source share

In iPython, you can remove the single variable, like this:

 del x 
+7
May 17 '17 at 9:07 a.m.
source share

Adding the following lines to a new script will clear all variables each time the script is re-run:

 from IPython import get_ipython get_ipython().magic('reset -sf') 

To make life easy, you can add it to your default template.

In Spyder: Tools>Preferences>Editor>Edit template

+2
Apr 13 '17 at 18:05
source share

The quit option in the console pane will also clear all variables in the variable explorer

*** Please note that you will lose all the code that you run in the console console

0
Oct 07 '17 at 10:49 on
source share



All Articles