2

I just migrated to Python from Matlab. I would appreciate your support. Thank you for your time.

In Matlab, when I start a script I always begin with "clear all' to empty the workspace. I use Spyder - Python 3.8 (Anaconda Distribution). I would like to clear the variables in Variables Explorer window before I begin a script. Could you please suggest on how can I achieve this?

In [1], a similar question is asked, but that does not include "clear all" command. I presently use an option suggested in [2], which is given below. I would like to know if this the optimal way to do it or is there a better method.

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

Reference:

  1. Python equivalent of Matlab's clear, close all, clc
  2. How do I clear all variables in the middle of a Python script?

0 Answers0