Inherits from
- Interpreter: wx.py.interpreter.Interpreter
Method summary
- __init__(self, locals = None, globals = None, rawin = None, stdin = sys.stdin, stdout = sys.stdout, stderr = sys.stderr)
- runcode(self, code)
- runcode_global(self, code)
- runsource(self, source, filename = '<input>', symbol = 'single')
- runsource_global(self, source, filename = '<input>', symbol = 'single')
Methods
- __init__(self, locals = None, globals = None, rawin = None, stdin = sys.stdin, stdout = sys.stdout, stderr = sys.stderr)
Constructor.
The optional 'locals' argument specifies a context in which the code is executed; it defaults to a newly created NumericContext. The optional globals argument is the global namespace for function evaluation. Note that, unlike locals, this must be dictionary. This is so that 'from xyz import *' will work.
The variable "__name__" is set to "__console__" and "__doc__" is set to None.
- runcode(self, code)
Execute a code object in the given context.
This is overloaded from the base class so that we can execute in both a global and a local context. We are using a "dictionary-like" object for the locals. The exec statement requires that the globals is a dict.
The rest of the code is cut/pasted from the base class.
- runcode_global(self, code)
Execute a code object in only the global context.
This method makes it possible to run "from xyz import *" from the command line. This isn't allowed if a non-dictionary local namespace is used. Note that this method will not work if the global dictionary
- runsource(self, source, filename = '<input>', symbol = 'single')
Compile and run some source in the interpreter.
- runsource_global(self, source, filename = '<input>', symbol = 'single')
Compile/run source in interpreter using only the global namespace.
Arguments are as for compile_command().
One several things can happen:
1) The input is incorrect; compile_command() raised an exception (SyntaxError or OverflowError). A syntax traceback will be printed by calling the showsyntaxerror() method.
2) The input is incomplete, and more input is required; compile_command() returned None. Nothing happens.
3) The input is complete; compile_command() returned a code object. The code is executed by calling self.runcode() (which also handles run-time exceptions, except for SystemExit).
The return value is True in case 2, False in the other cases (unless an exception is raised). The return value can be used to decide whether to use sys.ps1 or sys.ps2 to prompt the next line.