[What is]pycache?

Source: Internet
Author: User

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?

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.