Interpreter reset

sage.misc.reset.reset(vars=None, attached=False)

Delete all user-defined variables, reset all global variables back to their default states, and reset all interfaces to other computer algebra systems.

If vars is specified, just restore the value of vars and leave all other variables alone (i.e., call restore).

Note that the variables in the set sage.misc.reset.EXCLUDE are excluded from being reset.

INPUT:

  • vars - a list, or space or comma separated string (default: None), variables to restore
  • attached - boolean (default: False), if vars is not None, whether to detach all attached files

EXAMPLES:

sage: x = 5
sage: reset()
sage: x
x

sage: fn = tmp_filename(ext='foo.py')
sage: sage.misc.reset.EXCLUDE.add('fn')
sage: with open(fn, 'w') as f:
....:     _ = f.write('a = 111')
sage: attach(fn)
sage: [fn] == attached_files()
True
sage: reset()
sage: [fn] == attached_files()
True
sage: reset(attached=True)
sage: [fn] == attached_files()
False
sage: sage.misc.reset.EXCLUDE.remove('fn')
sage.misc.reset.reset_interfaces()
sage.misc.reset.restore(vars=None)

Restore predefined global variables to their default values.

INPUT:

  • vars - string or list (default: None), if not None, restores just the given variables to the default value.

EXAMPLES:

sage: x = 10; y = 15/3; QQ='red'
sage: QQ
'red'
sage: restore('QQ')
sage: QQ
Rational Field
sage: x
10
sage: y = var('y')
sage: restore('x y')
sage: x
x
sage: y
Traceback (most recent call last):
...
NameError: name 'y' is not defined
sage: x = 10; y = 15/3; QQ='red'
sage: ww = 15
sage: restore()
sage: x, QQ, ww
(x, Rational Field, 15)
sage: restore('ww')
sage: ww
Traceback (most recent call last):
...
NameError: name 'ww' is not defined