[Tutor] which file runs

Christopher Arndt chris.arndt at web.de
Sat Dec 2 02:59:07 CET 2006

Chris Hengge schrieb:
> My understanding is that whenever you run a script that has a newer.py,
> the .py runs, otherwise it automagically will use the .pyc

Not exactly. Whenever there is a .py file and no .pyc file is present or the
.pyc file is older, Python will read the .py file, compile it into bytecode and
execute that and also tries to write the bytecode to the .pyc file.

If there already is a .pyc file and it is newer, Python will use it directly.

(The rule is similar for .pyo files, which will be looked for/generated when
Python is started with the -O option).


More information about the Tutor mailing list