Original answer: Https://stackoverflow.com/questions/16869024/what-is-pycache
When you run a program in Python, the interpreter first compiles it into bytecode (which is an over-simplification) and stores it in the __pycache__ folder.
If you look over there you will find a bunch of names of the. py files in the file-sharing project folder, only their extension is. pyc or. Pyo.
These are the bytecode compiled versions of your program files and optimized bytecode compilation.
As a programmer, you can ignore it to a large extent ... All it does is make your program start a little faster.
When your scripts change, they will be recompiled, and if you delete the files or the entire folder and run your program again, they will reappear (unless you explicitly prohibit this behavior)
If you are using CPython (which is the most common because it is a reference implementation) and you do not need the folder, you can disable it by starting an interpreter with the-B flag
python -B foo.py
The order in which the Python interpreter works:
1 Complete the module loading and linking;
2 Compile the source code into a Pycodeobject object (that is, bytecode), write in memory for the CPU to read;
3 reads and executes from memory and writes Pycodeobject back to the hard disk, which is copied to the. pyc or. pyo file to save the bytecode file for all scripts in the current directory;
After 4, if the script is executed again, it first checks if there are any of these bytecode files locally and if the bytecode file is modified to match its script. is directly executed, otherwise repeat the above steps.
[What is]pycache?