Is there any way to know by which Python version the
You can get the magic number of your Python as follows:
$ python -V Python 2.6.2 # python >>> import imp >>> imp.get_magic().encode('hex') 'd1f20d0a'
To get the magic number for a pyc file you can do the following:
>>> f = open('test25.pyc') >>> magic = f.read(4) >>> magic.encode('hex') 'b3f20d0a' >>> f = open('test26.pyc') >>> magic = f.read(4) >>> magic.encode('hex') 'd1f20d0a'
By comparing the magic numbers you'll know the python version that generated the pyc file.