History of MAGIC number ?

Gregor Hoffleit flight at mathi.uni-heidelberg.de
Wed Jul 14 05:45:25 EDT 1999


I'd like to submit a patch to the maintainer of the Linux file command
so that file recognizes Python .pyc and .pyo files.

.pyc and .pyo files are quiet easily recognizable on their magic
number, a long word at the start of the file. The format of the long
word is 32bit little endian, with the higher 16 bits set to 0x0a0d and 
the lower 16 bits set to a pyc version number (20121 at the moment
in Python 1.5.2).

Now if I want to write a robust test method for file I could either
test for 0x0a0d in position 2 (which is not very rigid), or I had to
list the explicit versions, like

  0  lelong   0x0a0d4e99    compiled Python code, magic version 20121

Now the problem is that this verion number has changed quite a few
times in Python's history, but I can't find a list of the ancient
values anywhere (Misc/HISTORY only lists the times changes took place, 
but not the values).

Btw, should I say "Python bytecode" or "compiled Python code" ?

	Gregor




More information about the Python-list mailing list