SiteMap  | About    

Difference between .py and .pyc files?

Python compiles the .py files and saves it as .pyc files , so it can reference them in subsequent invocations. The .pyc contain the compiled bytecode of Python source files. The .pyc contain the compiled bytecode of Python source files, which is what the Python interpreter compiles the source to. This code is then executed by Python's virtual machine . There's no harm in deleting them (.pyc), but they will save compilation time if you're doing lots of processing.

Python is an interpreted language , as opposed to a compiled one, though the distinction can be blurry because of the presence of the bytecode compiler. Compiling usually means converting to machine code which is what runs the fastest. But interpreters take human readable text and execute it. They may do this with an intermediate stage .

For example, When you run source file, the python interpreter first looks to see if any 'myprog.pyc' (which is the byte-code compiled version of '') exists, and if it is more recent than ''. If so, the interpreter runs it. If it does not exist, or '' is more recent than it (meaning you have changed the source file), the interpreter first compiles '' to 'myprog.pyc'.

There is one exception to the above example. If you put '#! /usr/bin/env python' on the first line of '', make it executable , and then run '' by itself. (C) 2017    Founded by raps mk
All Rights Reserved. All other trademarks are property of their respective owners.