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 ?

有帮助吗?

解决方案

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.

其他提示

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 
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top