running python 2 vs 3

Mark H Harris harrismh777 at gmail.com
Thu Mar 20 18:42:05 CET 2014


On 3/20/14 12:23 PM, notbob wrote:

> What the heck is a .pyc file and how are they created?  Actually, I
> can see  it's a compiled binary, but I where did it come from?

The world according to me:  python is an interpreter (vs compiler) which 
converts your source code into tokens and then into a bytecode.

The process takes time. So, the solution is to place the tokenized stuff 
into a .pyc file so that the process does not have to be repeated 
unless, of course, the source has changed since the last .pyc file create.

It used to be that the .pyc files went into the same dir as the source 
(that's how it works for python2) but now with python3 they go into a 
directory in your source tree called __pycache__,  and they are named 
based on python version  (a way better scheme for sure).

If you wanted to you could run your python scripts from the .pyc file 
alone. In other words, you may import as long as the .pyc file exists 
and the source does not need to be there.  Some folks use this (not 
recommended) trick to hide or obfuscate their source from their users).

marcus





More information about the Python-list mailing list