How to process syntax errors

Chris Angelico rosuav at gmail.com
Tue Oct 11 04:19:48 EDT 2016


On Tue, Oct 11, 2016 at 7:02 PM, Pierre-Alain Dorange
<pdorange at pas-de-pub-merci.mac.com> 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.
>>
>> https://docs.python.org/3/library/functions.html#compile
>>
>> It's compiled.
>
> Using this function, the code is "compiled".
> I do not think this function is often used and most python project
> simply use the interpreter (which do a small translation into byte-code
> to be faster and check syntax error before running interpretation).

When you import, the same form of compilation is done. It always
happens. Python does not execute your raw source code - it'd be too
inefficient.

ChrisA



More information about the Python-list mailing list