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


Groups > comp.lang.python > #21475

Re: How to know that two pyc files contain the same code

References <mailman.544.1331390950.3037.python-list@python.org> <4f5bdb14$0$29891$c3e8da3$5496439d@news.astraweb.com>
Date 2012-03-11 12:15 +1100
Subject Re: How to know that two pyc files contain the same code
From Chris Angelico <rosuav@gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.554.1331428520.3037.python-list@python.org> (permalink)

Show all headers | View raw


On Sun, Mar 11, 2012 at 9:52 AM, Steven D'Aprano
<steve+comp.lang.python@pearwood.info> wrote:
> On Sat, 10 Mar 2012 15:48:48 +0100, Gelonida N wrote:
> Define "identical" and "the same".
>
> If I compile these two files:
>
>
> # file ham.py
> x = 23
> def func():
>    a = 23
>    return a + 19
>
>
>
> # file = spam.py
> def func():
>    return 42
>
> tmp = 19
> x = 4 + tmp
> del tmp
>
>
> do you expect spam.pyc and ham.pyc to count as "the same"?

They do not contain the same code. They may contain code which has the
same effect, but it is not the same code.

I don't think Python has the level of aggressive optimization that
would make these compile to the same bytecode, but if it did, then
they would _become identical_ per the OP's description - that they
contain identical bytecode. In fact, I think the OP defined it quite
clearly.

ChrisA

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

How to know that two pyc files contain the same code Gelonida N <gelonida@gmail.com> - 2012-03-10 15:48 +0100
  Re: How to know that two pyc files contain the same code Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-03-10 22:52 +0000
    Re: How to know that two pyc files contain the same code Chris Angelico <rosuav@gmail.com> - 2012-03-11 12:15 +1100
      Re: How to know that two pyc files contain the same code Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-03-11 07:06 +0000
        Re: How to know that two pyc files contain the same code Rick Johnson <rantingrickjohnson@gmail.com> - 2012-03-11 08:22 -0700
        Re: How to know that two pyc files contain the same code Gelonida N <gelonida@gmail.com> - 2012-03-12 00:56 +0100
    Re: How to know that two pyc files contain the same code Gelonida N <gelonida@gmail.com> - 2012-03-11 06:30 +0100

csiph-web