__pycache__, one more good reason to stck with Python 2?

Antoine Pitrou solipsis at pitrou.net
Wed Jan 19 10:00:20 EST 2011


On 19 Jan 2011 14:42:14 GMT
Steven D'Aprano <steve+comp.lang.python at pearwood.info> wrote:
> On Tue, 18 Jan 2011 00:58:14 -0800, jmfauth wrote:
> 
> > It is now practically impossible to launch a Python application via a
> > .pyc file. 
> 
> 
> When has that ever been possible?
> 
> 
> .pyc files are Python byte-code. You can't run them directly using Python 
> (except via the import machinery), you can't run them as a script, 
> they're not machine code. Unless you write a wrapper to import the file 
> as a module, you can't directly execute .pyc files.

It seems to work here:

$ echo "print 'foo'" > toto.py
$ python -m compileall -l .
Listing . ...
Compiling ./toto.py ...
$ rm toto.py
$ python toto.pyc
foo


But it still works under 3.2 even though the incantation is less pretty:

$ echo "import sys; print(sys.version)" > toto.py
$ __svn__/python -m compileall -l .
Listing . ...
Compiling ./toto.py ...
$ rm toto.py
$ __svn__/python __pycache__/toto.cpython-32.pyc
3.2rc1+ (py3k:88095M, Jan 18 2011, 17:12:15)
[GCC 4.4.3]


Regards

Antoine.





More information about the Python-list mailing list