code.compile_command()
code.compile_command() is a Python function in the Code Module category. Compiles a single Python command, detecting if it's complete or incomplete. The syntax is code.compile_command(source, filename="", symbol="single"). Returns: Code object or None or tuple. A typical example: code.compile_command("if x:") # Returns None (incomplete)
code.compile_command("if x:\n pass") # Returns code object. A close sibling is code.interact(), which starts an interactive Python interpreter (like a REPL). A close sibling is code.InteractiveInterpreter(), which embeds a Python interpreter into an application. More about this category: Interactive interpreter — interact, compile_command, InteractiveInterpreter. Related Code Module entries: code.interact(), code.InteractiveInterpreter(). This page is part of the free Python Reference documentation covering 978+ functions, methods, and modules with examples and parameter details. You can try code.compile_command() immediately in the Python playground, look up unfamiliar terms in the glossary, or return to the Python Reference homepage.