Search code examples
pythonpython-2.7pyc

python: Is there a way in python to delete the old .pyc before running the file


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 ?


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.