What is __pycache__?

648    Asked by ColinPayne in Python , Asked on Jun 8, 2021

what is __pycache__ ? 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 is it for?

Answered by Charles Parr

A __pycache__ folder is created when you use the line: import file_name. or try to get information from another file you have created. This makes it a little faster when running your program the second time to open the other file.



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.



Your Answer

Interviews

Parent Categories