Difference Between .py .pyc and pycache Files
.py, .pyc. _pycache_ Files
Python files are saved on the user machine with the file extension of “.py” as the C programing files are saved with .c extension and java files are saved with .java extensions. Python codes are then converted to bytecodes after they get interpreted. These bytecodes are saved in the file with the extension “.pyc”. The “_pycache_” files are the folder created to store the “.pyc” files. Let’s dig deeper on the Difference between .py .pyc and pycache files
Difference Between .py and .pyc Files.
Attribute | .py file | .pyc file |
---|---|---|
About | These files store the source code of the Python programs | These files store the bytecode of the Python programs |
Speed | Speed of the .py file is lower while generating output | Speed of the .pyc file is higher than the .py file as it contains the compiled codes. |
Code type | .py files store the human-readable high-level python code | .pyc files store the machine-readable low-level intermediate code |
Data Content |
Data in this file is interpreted by the interpreter of python
|
The data in this is the interpreted data which is ready to run on a virtual machine |
.py Files
.py extension used by the python to save the source code files. This is the script file format used by the python programing language. Python program can be written on any text editor but when we save the code with the extension “.py” the file is saved as the python file. These py files then can be executed on any machine where Python is installed. This file contains:
- High-level
- Human readable
- Python source code
As the .py file enter the interpreter a duplicate file is created with the same name but the different extension and different data format. .py files are slower in execution because the python is an interpreted language.
.pyc Files
.pyc extension is used to save the Interpreted bytecode. These type of files are created after the python source code are interpreted. Name of the file is the same as the name of the source code and are ready to run on a virtual machine. These files are faster in generating output as compared to .py files. “.pyc” files are:
- Faster
- Machine-readable
- Low-level
- Intermediate code
.pyc files are stored in a specific folder and are only created when the python source code is compiled. As these files are already interpreted speed of these files are faster than .py files.
_pycache_ Files
All the interpreted files are stored in the _pycache_ files. We can say _pycache_ file is a folder containing all the interpreted .pyc files. The data in .pyc files in the _pycahce _ folder the is the bytecode representation of the python source code.
Prime Course Trailer
Related Banners
Get PrepInsta Prime & get Access to all 200+ courses offered by PrepInsta in One Subscription
Get over 200+ course One Subscription
Courses like AI/ML, Cloud Computing, Ethical Hacking, C, C++, Java, Python, DSA (All Languages), Competitive Coding (All Languages), TCS, Infosys, Wipro, Amazon, DBMS, SQL and others
Login/Signup to comment