Common Interface Functionality

See the examples in the other sections for how to use specific interfaces. The interface classes all derive from the generic interface that is described in this section.

AUTHORS:

  • William Stein (2005): initial version
  • William Stein (2006-03-01): got rid of infinite loop on startup if client system missing
  • Felix Lawrence (2009-08-21): edited ._sage_() to support lists and float exponents in foreign notation.
class sage.interfaces.expect.AsciiArtString
Bases: str
class sage.interfaces.expect.Expect(name, prompt, command=None, server=None, server_tmpdir=None, ulimit=None, maxread=100000, script_subdirectory='', restart_on_ctrlc=False, verbose_start=False, init_code=[], max_startup_time=None, logfile=None, eval_using_file_cutoff=0, do_cleaner=True, remote_cleaner=False, path=None)

Bases: sage.structure.parent_base.ParentWithBase

Expect interface object.

call(function_name, *args, **kwds)
clear(var)
Clear the variable named var.
clear_prompts()
console()
cputime()
CPU time since this process started running.
eval(code, strip=True, synchronize=False, locals=None, **kwds)

INPUT:

  • code - text to evaluate
  • strip - bool; whether to strip output prompts, etc. (ignored in the base class).
  • locals - None (ignored); this is used for compatibility with the Sage notebook’s generic system interface.
  • **kwds - All other arguments are passed onto the _eval_line method. An often useful example is reformat=False.
execute(*args, **kwds)
expect()
function_call(function, args=None, kwds=None)

EXAMPLES:

sage: maxima.quad_qags(x, x, 0, 1, epsrel=1e-4)
[0.5,5.5511151231257...e-15,21,0]
sage: maxima.function_call('quad_qags', [x, x, 0, 1], {'epsrel':'1e-4'})
[0.5,5.5511151231257...e-15,21,0]
get(var)
Get the value of the variable var.
get_using_file(var)

Return the string representation of the variable var in self, possibly using a file. Use this if var has a huge string representation, since it may be way faster.

Warning

In fact unless a special derived class implements this, it will not be any faster. This is the case for this class if you’re reading it through introspection and seeing this.

help(s)
interact()

This allows you to interactively interact with the child interpreter. Press Ctrl-D or type ‘quit’ or ‘exit’ to exit and return to Sage.

Note

This is completely different than the console() member function. The console function opens a new copy of the child interpreter, whereas the interact function gives you interactive access to the interpreter that is being used by Sage. Use sage(xxx) or interpretername(xxx) to pull objects in from sage to the interpreter.

interrupt(tries=20, timeout=0.29999999999999999, quit_on_fail=True)
is_local()
is_remote()
is_running()
Return True if self is currently running.
name(new_name=None)
new(code)
path()
pid()
quit(verbose=False, timeout=0.25)

EXAMPLES:

sage: a = maxima('y')
sage: maxima.quit()
sage: a._check_valid()
...
ValueError: The maxima session in which this object was defined is no longer running.
read(filename)

EXAMPLES:

sage: filename = tmp_filename()
sage: f = open(filename, 'w')
sage: f.write('x = 2\n')
sage: f.close()
sage: octave.read(filename)  #optional -- requires Octave
sage: octave.get('x')        #optional
' 2'
sage: import os
sage: os.unlink(filename)
set(var, value)
Set the variable var to the given value.
user_dir()
class sage.interfaces.expect.ExpectElement(parent, value, is_name=False, name=None)

Bases: sage.structure.element.RingElement

Expect element.

attribute(attrname)

If this wraps the object x in the system, this returns the object x.attrname. This is useful for some systems that have object oriented attribute access notation.

EXAMPLES:

sage: g = gap('SO(1,4,7)')
sage: k = g.InvariantQuadraticForm()
sage: k.attribute('matrix')
[ [ 0*Z(7), Z(7)^0, 0*Z(7), 0*Z(7) ], [ 0*Z(7), 0*Z(7), 0*Z(7), 0*Z(7) ], 
  [ 0*Z(7), 0*Z(7), Z(7), 0*Z(7) ], [ 0*Z(7), 0*Z(7), 0*Z(7), Z(7)^0 ] ]
sage: e = gp('ellinit([0,-1,1,-10,-20])')
sage: e.attribute('j')
-122023936/161051
bool()
gen(n)
get_using_file()

Return this element’s string representation using a file. Use this if self has a huge string representation. It’ll be way faster.

EXAMPLES:

sage: a = maxima(str(2^1000))
sage: a.get_using_file()
'10715086071862673209484250490600018105614048117055336074437503883703510511249361224931983788156958581275946729175531468251871452856923140435984577574698574803934567774824230985421074605062371141877954182153046474983581941267398767559165543946077062914571196477686542167660429831652624386837205668069376'
hasattr(attrname)

Returns whether the given attribute is already defined by this object, and in particular is not dynamically generated.

EXAMPLES:

sage: m = maxima('2')
sage: m.hasattr('integral')
True
sage: m.hasattr('gcd')
False
name(new_name=None)

Returns the name of self. If new_name is passed in, then this function returns a new object identical to self whose name is new_name.

Note that this can overwrite existing variables in the system.

EXAMPLES:

sage: x = r([1,2,3]); x
[1] 1 2 3
sage: x.name()
'sage3'
sage: x = r([1,2,3]).name('x'); x
[1] 1 2 3
sage: x.name()
'x'
sage: s5 = gap.SymmetricGroup(5).name('s5')
sage: s5
SymmetricGroup( [ 1 .. 5 ] )
sage: s5.name()
's5'
sage()

Attempt to return a Sage version of this object.

EXAMPLES:

sage: gp(1/2).sage()
1/2
sage: _.parent()
Rational Field
class sage.interfaces.expect.ExpectFunction(parent, name)

Bases: sage.structure.sage_object.SageObject

Expect function.

class sage.interfaces.expect.FunctionElement(obj, name)

Bases: sage.structure.sage_object.SageObject

Expect function element.

help()
exception sage.interfaces.expect.PropTypeError
Bases: exceptions.Exception
sage.interfaces.expect.console(cmd)
class sage.interfaces.expect.gc_disabled

Bases: object

This is a “with” statement context manager. Garbage collection is disabled within its scope. Nested usage is properly handled.

EXAMPLES:

sage: import gc
sage: from sage.interfaces.expect import gc_disabled
sage: gc.isenabled()
True
sage: with gc_disabled():
...       print gc.isenabled()
...       with gc_disabled():
...           print gc.isenabled()
...       print gc.isenabled()
False
False
False
sage: gc.isenabled()
True
sage.interfaces.expect.is_ExpectElement(x)
sage.interfaces.expect.reduce_load(parent, x)
sage.interfaces.expect.tmp_expect_interface_local()

Previous topic

Interpreter Interfaces

Next topic

Interface to Axiom

This Page