Ask Your Question

Clearing all user-defined variables from current session

asked 2012-12-20 10:10:01 -0500

Louisa Grey gravatar image

I'm using Sage from the interactive shell. How can I clear/remove all the variables I have defined so far in my current session?

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2012-12-20 11:44:49 -0500

DSM gravatar image

You can use reset():

sage: a = 3
sage: a
sage: reset()
sage: a
NameError                                 Traceback (most recent call last)
NameError: name 'a' is not defined

You can also give variable names, like reset("a b c") and so on. Type reset? at the console for the details.

edit flag offensive delete link more


Doing this in Sage 7.6 gives:

sage: a=2; a
sage: reset()
sage: a
Traceback (most recent call last):
NameError: name 'a' is not defined
sage: quit
Traceback (most recent call last):
NameError: name 'quit' is not defined

This issue is considered in this ticket: reset does not restore "quit"

jipilab gravatar imagejipilab ( 2017-03-29 10:41:00 -0500 )edit

%reset -s looks like a potentially better way to do this.

John Palmieri gravatar imageJohn Palmieri ( 2017-03-30 12:47:47 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools


Asked: 2012-12-20 10:10:01 -0500

Seen: 4,002 times

Last updated: Dec 20 '12