Python bytecode compatibility between interpreter versions

Roger Binns rogerb at rogerbinns.com
Sun Mar 21 12:48:40 EST 2004


> > You are considering Python .pyc files and Java class files to be
> > the same thing.  They aren't.
>
> They're not 'the same thing'.  They are roughly analogous to one
> another though, wouldn't you say?

No.  I explained it further in the message.

> Huh??  .pyc files are an "implementation detail of the Python
> interpreter"?   Care to expound further?  'Coz that sounds
> pretty nonsensical...

One version of a compliant Python interpretter happens to use
these files, and expose that they exist.  They are generated on
demand and automatically updated.  The Python interpretter could
have stored them elsewhere on the filesystem (for example in
a hidden "cache" directory), but for simplicity's sake stored
them alongside the source file.

Go ahead and write protect the directories containing your
Python source (after deleting all .pyc files).  You will find
everything runs just fine without any visible .pyc files.

If you write your own Python interpretter/compiler, it will be
considered compliant if it implements the language correctly.
There is *nothing* about bytecodes, or bytecode compatibility.
For example if you wanted to write your own that ran on top of
Java, you would probably just directly generate class files.
If you wrote one that ran on a Palm device you would do something
else.  It is up to your implementation what it does.  The
only requirement would be working with Python *source* files.

Roger





More information about the Python-list mailing list