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

Steven D'Aprano steve+comp.lang.python at pearwood.info
Thu Jan 20 19:02:41 EST 2011


On Thu, 20 Jan 2011 05:09:50 -0800, John Pinner wrote:

> Hi
> 
> You have disturbe my slumber, Steven ;-)
> 
> On Jan 19, 2:42 pm, Steven D'Aprano <steve
> +comp.lang.pyt... 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.
> 
> Not true. 'python myprog.pyc' has worked for as long as I have been
> using Python. Whether or not it is a good idea is another matter.
> 
> Probably it would be best to check what you're saying before posting
> such a bald assertion, even though you were 110% sure of what you were
> saying. I've been there, done that, bought the tee-shirt.

Yes, thank you, I've already been corrected over this :)

But you got me thinking... how far back does this behaviour go? 
Apparently it goes back as long as I've been using Python too:

[steve at sylar ~]$ echo "print 'spam spam spam'" > spam.py
[steve at sylar ~]$ python1.5
Python 1.5.2 (#1, Apr  1 2009, 22:55:54)  [GCC 4.1.2 20070925 (Red Hat 
4.1.2-27)] on linux2
Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam
>>> import spam
spam spam spam
>>>
[steve at sylar ~]$ python1.5 spam.pyc
spam spam spam


But of course, .pyc files1.5 are version specific:


[steve at sylar ~]$ python2.5 spam.pyc
RuntimeError: Bad magic number in .pyc file


-- 
Steven



More information about the Python-list mailing list