/  Technology   /  If Python is interpreted, what are .pyc files?
If Python is interpreted, what are .pyc files

If Python is interpreted, what are .pyc files?


CPython, an implementation of Python in C, compiles the source code into a lower level bytecode. This bytecode is later executed by the Virtual Machine. 


The .pyc file is the compiled byte code python file, whereas, the .py file is the source file. 


When we first save a Python source code file, it gets saved as a .py file and once we execute it, it creates a .pyc file which has the byte code of that particular source code. This .pyc file is stored on to disk and is used to reduce the time in compiling the source code again to the bytecode. 


For example, when we deal with modules once we import the module and execute the code, a .pyc file is saved of this imported module. If we use this module again, the already existing .pyc file is used and directly executed without compiling.


A language can simply never be called if it’s an interpreted or a compiled one, it completely depends upon the implementation of the language. There is no such thing as an interpreted language. Every language can be implemented by either an interpreter or a compiler or a combination of both or even multiple compilers. 


There are many Python implementations such as IronPython, Jython, PyPy, CPython, Stackless Python and many more. Each of these implementations uses a compiler and not one in the above list is purely interpreted. 


So in conclusion, .pyc file is a bytecode file that is compiled by Cpython and which is ready to be executed by any Virtual Machine. 


Leave a comment