Ask Your Question

Clearing all user-defined variables from current session

asked 2012-12-20 17:10:01 +0100

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 18:44:49 +0100

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 17:41:00 +0100 )edit

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

John Palmieri gravatar imageJohn Palmieri ( 2017-03-30 19:47:47 +0100 )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 17:10:01 +0100

Seen: 5,371 times

Last updated: Dec 20 '12