Question

It seems that sometimes when I pull from the git the old .pyc runs instead of the new pulled .py file is there a way to automatically clear the .pyc file so it runs always the fresh version ?

Was it helpful?

Solution

The old .pyc is automatically cleared by Python, provided the modified date on the .py file is newer.

You could manually delete all .pyc files in a directory structure with:

find . -name \*.pyc -delete

and Python will re-create them as modules are imported. You can also run:

python -m compileall .

to force a compilation.

OTHER TIPS

Another option to prevent the creation of .pyc file is to pass options -B to python

python -B file.py

-B option from man:

-B     Don't write .py[co] files on import. See also PYTHONDONTWRITEBYTECODE.

also you can specify it at the beginning of the .py file with sha-bang:

#!/bin/python -B 
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top