Python codeop Module
Example
Detect if a string is a complete statement:
import codeop
cc = codeop.compile_command("x = 1")
print(cc is not None)
Try it Yourself »
Definition and Usage
The codeop module provides utilities to compile possibly-incomplete code.
Use it to implement interactive interpreters that accept multi-line statements.
Members
Member | Description |
---|---|
compile_command() | Compile a command and return a code object or None if incomplete. |
CommandCompiler | Callable class that behaves like compile_command with state. |