[Tutor] Version of a .pyc file
Terry Carroll
carroll at tjc.com
Wed Apr 19 01:01:28 CEST 2006
On Tue, 18 Apr 2006, Don Taylor wrote:
> How can I tell if a .pyc file was built with 2.3 or 2.4?
There's a "Magic Number" in the first 2 or 4 bytes, (depending on whether
you consider the \r\n part of the MN).
>>> f = open("pycfile.pyc", "rb")
>>> magictable = {'\x3b\xf2\r\n': "2.3", '\x6d\xf2\r\n' : "2.4"}
>>> magic = f.read(4)
>>> release = magictable.get(magic,"unknown")
>>> print "Python release:", release
Python release: 2.4
More information about the Tutor
mailing list