How to process syntax errors

BartC bc at freeuk.com
Mon Oct 10 13:48:35 EDT 2016


On 10/10/2016 16:44, Pierre-Alain Dorange wrote:
> Chris Angelico <rosuav at gmail.com> wrote:
>
>> Yes and no. Syntax errors are detected when the script is compiled, so
>> you can't do something like this:
>
> You're right, except that Python is never compiled, it was just checked
> for syntax error before interpreting code.

In the case of CPython, source code is compiled into byte-code before 
it's interpreted. Part of that process is detecting syntax errors.

AFAIK, this is usually done a module at a time (convert an entire module 
to byte-code, then start interpreting). It might be a little different 
with functions such as eval and exec.

-- 
Bartc



More information about the Python-list mailing list