[Python-Dev] Python interpreter crash.

Tim Peters tim.one@comcast.net
Tue, 12 Mar 2002 23:30:12 -0500


[Guido]
> f = open("foo.pyc")
> f.seek(8)
> code = marshal.load(f)

[Greg Ewing]
> Ah! I was trying to do something like that a minute ago before
> answering the original query, but the magic number 8 eluded me. Is it
> documented anywhere, or is mystic knowledge required?

Mystic knowledge:  these are internal implementation details, and not
formally guaranteed across releases.

The first 4 bytes of a .py[co] are a "magic number", and the next 4 a
timestamp.  That the first 4 bytes hold a magic number is documented with
PyImport_GetMagicNumber().  I'm not sure the timestamp part is documented
anywhere in the manuals; it can be guessed from staring at
Tools/scripts/checkpyc.py or Lib/py_compile.py.