clear shell command

6,119 views
Skip to first unread message

Duim

unread,
Mar 19, 2010, 6:39:02 AM3/19/10
to spyder
First of all: I really like Spyder and use it all the time.

question: Is there a command within Spyder to clear the shell and the
workspace?

Pierre Raybaut

unread,
Mar 21, 2010, 6:14:49 AM3/21/10
to spyder
In "Interactive console" menu: click on "Restart Python interpreter".

Cheers,
Pierre

Duim

unread,
Mar 23, 2010, 10:11:49 AM3/23/10
to spyder
ok, thank you.

There isn't a command which I can use in my python script?

I would like the same for a "clear workspace"

Reason I'm asking is that I'm using Spyder often like I used to use
Matlab and I'm looking for the same thing as matlab functions "clear
all" and "clc".

William Gardiner

unread,
Mar 3, 2014, 12:49:47 PM3/3/14
to spyd...@googlegroups.com, bauke...@gmail.com
from http://scientificcomputingco.blogspot.com/2013/10/python-spyder-clear-workspaceshell.html
add the following to C:/Python27/Lib/site-packages/spyderlib/scientific_startup.py (I inserted it at the end of the file)

#==================
#===================
def clear():
        '''Clears the shell of the spyder application
        Use either clear() or cls()'''
        os.system('cls')
        return None
cls = clear

def clear_all():
    '''Clears all the variables from the workspace of the spyder application.'''
    cls()
    gl = globals().copy()
    for var in gl:
        if var[0] == '_': continue
        if 'func' in str(globals()[var]): continue
        if 'module' in str(globals()[var]): continue

        del globals()[var]

setscientific()
del setscientific
clear_all()
print 'Type "scientific" for more details.'

I'm getting an error saying that setscientific() is not defined though when I start spyder and an error saying "The system cannot find the path specified" when I run the clear_all() command.
But it seems to work regardless, clears all the variables from the Variable Explorer.

wxwac...@gmail.com

unread,
Mar 10, 2014, 7:19:25 PM3/10/14
to spyd...@googlegroups.com, bauke...@gmail.com
If you want to clear the shell in order to avoid confusing different outputs you can use something like print('n'*1000)  in your script as shorter yet less elegant alternative to the os.system call.
Altertanively you could use an Ipython console which features numbered outputs.

Restarting the Python Interpreter will reset both shell and workspace.
So what about a "Clear Console" option in the "Interactive console" menu similar to the Clear button of GIMP's Python console?


Ryan Clary

unread,
Mar 10, 2014, 9:22:47 PM3/10/14
to spyd...@googlegroups.com
Ctrl+. Restarts an IPython console, don't know if that helps.

Ryan Clary
--
You received this message because you are subscribed to the Google Groups "spyder" group.
To unsubscribe from this group and stop receiving emails from it, send an email to spyderlib+...@googlegroups.com.
To post to this group, send email to spyd...@googlegroups.com.
Visit this group at http://groups.google.com/group/spyderlib.
For more options, visit https://groups.google.com/d/optout.

Carlos L. Hernández-Cedillo

unread,
Jul 29, 2015, 7:26:22 PM7/29/15
to spyder, bauke...@gmail.com
%reset
Reply all
Reply to author
Forward
0 new messages