Language and Compiler Modules
codeop
Helps interactive tools distinguish complete code from input that needs additional lines. compile_command returns a code object for a complete command or None for incomplete input; invalid syntax raises an exception. CommandCompiler remembers future flags across calls. Compilation itself does not execute the code.
Formal Syntax & Structure
python syntaxpython
import codeopReturn Value
module
Module namespace available through import; import is a statement, not a value-returning expression.
Working Example
Example Snippetpython
from codeop import compile_commandprint(compile_command("if True:") is None)print(compile_command("x = 2") is not None)