0 votes
1 view
in Python by (47.8k points)

From what I understand, a cache is an encrypted file of similar files.

What do we do with the __pycache__ folder? Is it what we give to people instead of our source code? Is it just my input data? This folder keeps getting created, what it is for?

1 Answer

0 votes
by (107k points)

At the time when you run a program in python, the interpreter compiles it to bytecode first and after compilation interpreter stores it in the __pycache__ folder. So when you look in there you will find a bunch of files sharing the names of the .py files in your project's folder, you will see that their extensions will be either .pyc or .pyo. These files are bytecode-compiled and optimized bytecode-compiled versions of your program's files, respectively.

__pycache__ makes your program to start a little faster. When your scripts change, they will be recompiled, and if you delete the files or the whole folder and run your program again, they will reappear (unless you specifically suppress that behaviour)

If you are using CPython which is the most common, as it is the reference implementation, so you don't want that folder, then you can suppress it by starting the interpreter with the -B flag, for example:-

python -B foo.py

Related questions

Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...