exec()
A built-in function that runs a string of Python source code as statements, used in labs to show an error without stopping the whole program.
In more detail
Errors in the code it runs are raised at the exec call, so a try statement around it can catch even a SyntaxError. compile() with the mode 'exec' checks the same source without running it. Never pass exec text from an untrusted user.
Related terms
- eval — A shell builtin that joins its arguments into one string and runs that string as a command, as if you had typed it.
- syntax error — A mistake in the form of code, such as an unclosed bracket or an if without its matching end, that the language cannot understand and so will not run.
- try statement — The statement that runs a block of code and, if a listed exception happens there, runs an except block instead of letting the program stop.
Taught in
- Interpreter, Compiler, And What Counts As Syntax — PCEP Certified Entry-Level Python Programmer (PCEP-30-02) Exam Prep
- Parameters, Arguments And Scope — PCEP Certified Entry-Level Python Programmer (PCEP-30-02) Exam Prep
- Try, Except, Else And Finally — PCEP Certified Entry-Level Python Programmer (PCEP-30-02) Exam Prep