How to know that two pyc files contain the same code

Discussion in 'Python' started by Gelonida N, Mar 10, 2012.

  1. Gelonida N

    Gelonida N Guest

    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.
    Gelonida N, Mar 10, 2012
    #1
    1. Advertising

  2. Gelonida N

    Bl0ckeduser Guest

    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.
    Bl0ckeduser, Mar 10, 2012
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. gelonida
    Replies:
    1
    Views:
    739
    Gabriel Genellina
    May 6, 2010
  2. Roger Pack
    Replies:
    3
    Views:
    148
    Roger Pack
    Sep 28, 2010
  3. Gelonida N
    Replies:
    6
    Views:
    181
    Gelonida N
    Mar 11, 2012
  4. Andries

    I know, I know, I don't know

    Andries, Apr 23, 2004, in forum: Perl Misc
    Replies:
    3
    Views:
    222
    Gregory Toomey
    Apr 23, 2004
  5. Jason Carlton
    Replies:
    11
    Views:
    236
    Dr J R Stockton
    Dec 8, 2009
Loading...

Share This Page