find out whther byte two .pyc files contain the same byte code.

Gabriel Genellina gagsl-py2 at yahoo.com.ar
Wed May 5 19:04:23 EDT 2010


En Wed, 05 May 2010 10:34:34 -0300, gelonida <gelonida at gmail.com> escribió:

> I'd like to know whether the byte code of two .pyc files is identical.
>
> I thought, I could just compare the md5sums of thw .pyc files.
> However this does not work.
>
> It seems, that .pyc ontains the time stamp of the source file.
> the .pyc file changes its contents when I don't change the file's
> contents but just
> save it again.

Yes, that's what happens.
First 4 bytes in a .pyc file contain a "magic" number identifying the  
Python version used to create it. Next 4 bytes contain the timestamp of  
the source file.

Just ignore the first 8 bytes when computing the checksum:

tail -c +8 tst.pyc | md5sum

(untested)

-- 
Gabriel Genellina




More information about the Python-list mailing list