What is the difference between .py and .pyc files?

The major difference is that .py files are Python source files while .pyc files are the compiled bytecode files that are generated by the Python compiler. Python compiles the .py files and saves it as .pyc files. The .pyc contain the compiled bytecode of Python source files.

For example, When you run code.py source file, the python interpreter first looks to see if any 'code.pyc'  exists, and if it is more recent than 'code.py'. If so, the interpreter execute it. If it not exist, the interpreter first compiles 'code.py' to 'code.pyc'.

Total Views: 1356