This function is useful for programs that want to emulate Python'sinterpreter main loop (a.k.a. the read-eval-print loop). The trickypart is to determine when the user has entered an incomplete commandthat can be completed by entering more text (as opposed to acomplete command or a syntax error). This functionalmost always makes the same decision as the real interpretermain loop.source is the source string;filename is the optionalfilename from which source was read, defaulting to'<input>';andsymbol is the optional grammar start symbol, which shouldbe either'single' (the default) or'eval'.
Returns a code object (the same ascompile(source,filename,symbol)) if the command is complete andvalid;None if the command is incomplete; raisesSyntaxError if the command is complete and contains asyntax error, or raisesOverflowError orValueError if the command contains an invalid literal.