Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #21455 > unrolled thread

How to know that two pyc files contain the same code

Started byGelonida N <gelonida@gmail.com>
First post2012-03-10 15:49 +0100
Last post2012-03-10 10:08 -0500
Articles 2 — 2 participants

Back to article view | Back to comp.lang.python


Contents

  How to know that two pyc files contain the same code Gelonida N <gelonida@gmail.com> - 2012-03-10 15:49 +0100
    Re: How to know that two pyc files contain the same code Bl0ckeduser <bl0ckedusersoft@gmail.com> - 2012-03-10 10:08 -0500

#21455 — How to know that two pyc files contain the same code

FromGelonida N <gelonida@gmail.com>
Date2012-03-10 15:49 +0100
SubjectHow to know that two pyc files contain the same code
Message-ID<mailman.545.1331391007.3037.python-list@python.org>
Hi,

I want to know whether two .pyc files are identical.

With identical I mean whether they contain the same byte code.

Unfortunately it seems, that .pyc files contain also something like the
time stamp of the related source file.

So though two pyc files contain the same byte code, they will not be
byte identical.

One option, that I found is to use
python -m unpyclib.application -d filename.pyc and check whether the
results are identical.


However even this will fail if the files were not compiled under the
same absolute path name as the source filename is contained twice  (at
least for my trivial example) in the disassemblers output.


Thanks a lot for any other idea.


[toc] | [next] | [standalone]


#21456

FromBl0ckeduser <bl0ckedusersoft@gmail.com>
Date2012-03-10 10:08 -0500
Message-ID<jjfqp6$40i$1@dont-email.me>
In reply to#21455
Gelonida N wrote:
> Hi,
>
> I want to know whether two .pyc files are identical.
>
> With identical I mean whether they contain the same byte code.
>
> Unfortunately it seems, that .pyc files contain also something like the
> time stamp of the related source file.
>
> So though two pyc files contain the same byte code, they will not be
> byte identical.
>
> One option, that I found is to use
> python -m unpyclib.application -d filename.pyc and check whether the
> results are identical.
>
>
> However even this will fail if the files were not compiled under the
> same absolute path name as the source filename is contained twice  (at
> least for my trivial example) in the disassemblers output.
>
>
> Thanks a lot for any other idea.
>

Try using the disassembler code here:

http://nedbatchelder.com/blog/200804/the_structure_of_pyc_files.html

and removing from it the parts which print out the timestamp and the 
absolute path. (Two different lines in the source). That seems to work 
for me.


[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web