30.1. code
code read-eval-print (--)Python
-
class
code.InteractiveConsole(locals=None, filename="<console>") Python
InteractiveInterpretersys.ps1sys.ps2
-
code.interact(banner=None, readfunc=None, local=None, exitmsg=None) read-eval-print
InteractiveConsolereadfuncInteractiveConsole.raw_input()localInteractiveConsoleinteract()banner exitmsg3.6 : exitmsg .
-
code.compile_command(source, filename="<input>", symbol="single") Python(read-eval-print)()
source filename
'<input>'symbol'single'()'eval'(
compile(source, filename, symbol))NoneSyntaxErrorOverflowErrorValueError
30.1.1.
-
InteractiveInterpreter.runsource(source, filename="<input>", symbol="single") compile_command()filename'<input>'symbol'single':-
compile_command()(SyntaxErrorOverflowError)showsyntaxerror()runsource()False -
compile_command()Nonerunsource()True -
compile_command()(SystemExit)runcode()runsource()False
sys.ps1sys.ps2-
-
InteractiveInterpreter.showsyntaxerror(filename=None) filename Python
'<string>'write()
30.1.2.
InteractiveConsole InteractiveInterpreter
-
InteractiveConsole.interact(banner=None, exitmsg=None) Python banner Python (!)
exitmsg exitmsg
None3.4 :
3.6 :
-
InteractiveConsole.raw_input(prompt="") EOF
EOFErrorsys.stdin