Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
# cython: old_style_globals=True """ Interpreter reset """ from __future__ import absolute_import
import sys
# Exclude these from the reset command. # DATA, base64 -- needed by the notebook # Add exit and quit to EXCLUDE to resolve trac #22529 and trac #16704 EXCLUDE = set(['sage_mode', '__DIR__', 'DIR', 'DATA', 'base64', 'exit', 'quit'])
def 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')
TESTS:
Confirm that assumptions don't survive a reset (:trac:`10855`)::
sage: assume(x > 3) sage: assumptions() [x > 3] sage: bool(x > 3) True sage: reset() sage: assumptions() [] sage: bool(x > 3) False
""" except KeyError: pass
def 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 """ import sage.all D = sage.all.__dict__ else: elif mode == 'notebook': import sage.all_notebook D = sage.all_notebook.__dict__ else: import sage.all D = sage.all.__dict__
def _restore(G, D, vars): else: else: else: pass
def reset_interfaces(): |