Python code is compiled before execution (was: How to process syntax errors)

Ben Finney ben+python at benfinney.id.au
Tue Oct 11 04:28:14 EDT 2016


pdorange at pas-de-pub-merci.mac.com (Pierre-Alain Dorange) writes:

> Chris Angelico <rosuav at gmail.com> wrote:
>
> > https://docs.python.org/3/library/functions.html#compile
> > 
> > [Python code is] compiled.
>
> Using this function, the code is "compiled".

You have it backward: Python code is compiled. That's what the Python
runtime requires. It often happens automatically, but it happens for all
Python code that gets executed.

What that function does is allow you to *separately* compile the Python
code.

> 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).

The “small translation into byte-code” *is* compilation.

Don't make the mistake that the only product of “compile” is some CPU
code; that is a foolishly narrow definition.

(Good sigmonster, have a cookie.)

-- 
 \      “[I]t is impossible for anyone to begin to learn that which he |
  `\                thinks he already knows.” —Epictetus, _Discourses_ |
_o__)                                                                  |
Ben Finney




More information about the Python-list mailing list