3.21 code -- Code object services.

The code module defines operations pertaining to Python code objects. It defines the following function:

compile_command (source, [filename[, symbol]])
This function is useful for programs that want to emulate Python's interpreter main loop (a.k.a. the read-eval-print loop). The tricky part is to determine when the user has entered an incomplete command that can be completed by entering more text (as opposed to a complete command or a syntax error). This function almost always makes the same decision as the real interpreter main loop.

Arguments: source is the source string; filename is the optional filename from which source was read, defaulting to '<input>'; and symbol is the optional grammar start symbol, which should be either 'single' (the default) or 'eval'.

Return a code object (the same as compile(source, filename, symbol)) if the command is complete and valid; return None if the command is incomplete; raise SyntaxError if the command is a syntax error.


Send comments on this document to python-docs@python.org.


Banner.Novgorod.Ru