Menu

Compile only if .pyc is out-of-date?

Reddit r/learnpython·u/RomfordNavy·6 months ago
#vYTp3d7r
#compile#file#date#exec#py_compile
Reading 0:00
15s threshold

Is there some way I can compile a .py script into a .pyc but only if it is missing or out-of-date with the.py file?

I am trying to compile the file if necessary and then run it from within Python, can exec() run a .pyc file?

import py_compile py_compile.compile('Child.py') exec(open('Child.py').read()) 

This works but recompiles the file on every run.