Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

You may use show_identifiers:

sage: show_identifiers()
['In', 'Out', 'exit', 'get_ipython', 'quit']
sage: a = 2
sage: def function_square(b):
....:     return b^2
....: 
sage: show_identifiers()
['In', 'Out', 'a', 'exit', 'function_square', 'get_ipython', 'quit']

Then using the locals() which returns a dictionary containing the current scope's local variables, you can recover the objects:

sage: D = locals()
sage: D['a']
2
sage: D['function_square']
<function function_square at 0x7fa7ddd35f50>
sage: D['quit']
<IPython.core.autocall.ExitAutocall object at 0x7fa94bc4fa90>

These tools are used by the save_session function in Sage.

You may use show_identifiers:

sage: show_identifiers()
['In', 'Out', 'exit', 'get_ipython', 'quit']
sage: a = 2
sage: def function_square(b):
....:     return b^2
....: 
sage: show_identifiers()
['In', 'Out', 'a', 'exit', 'function_square', 'get_ipython', 'quit']

Then using the locals() which returns a dictionary containing the current scope's local variables, you can recover the objects:

sage: D = locals()
sage: D['a']
2
sage: D['function_square']
<function function_square at 0x7fa7ddd35f50>
sage: D['quit']
<IPython.core.autocall.ExitAutocall object at 0x7fa94bc4fa90>

These tools are used by the save_session function in Sage.

EDIT June 5th 2018: Another option is to use magic IPython functions %who and %whos :

sage: %who
a    function_square     
sage: %whos
Variable          Type        Data/Info
---------------------------------------
a                 Integer     2
function_square   function    <function function_square at 0x7f28cfb2ac08>