/  Technology   /  Python-What is __pycache__?
Python-What is __pycache__?

Python-What is __pycache__?

What do we do with the __pycache__ folder? What we share to people is _pycache_ folder or instead of our source code? This folder is getting created, and is it my input data and what it is for?

At the point when you run a program in python, the interpreter compiles it to bytecode first and stores it in the __pycache__ folder. If you go through there you will find a lot of files sharing the names of the .py files in your project’s folder, just their extensions will be either .pyc or .pyo. These are optimized and bytecode-compiled versions of your program’s files.

As a developer, to a great extent you can just ignore it… Everything it does is make your program start a little faster. When your snippets change, they will be recompiled, and if you erase or delete the files or the entire folder and run your program again, they will appear again unless you specifically suppress that behavior.

When you’re sharing your code to others, the common practice is to delete that folder, but it doesn’t generally make a difference whether you do or don’t.

On the off chance that you are using CPython which is the most common, as it is the reference usage, so you don’t want that folder, then you can suppress it by starting the interpreter with the -B flag, for instance:-

 

python -B foo.py

Leave a comment