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


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

Question about output different with command dis.dis(code)

Started byfl <rxjwg98@gmail.com>
First post2015-11-26 01:02 -0800
Last post2015-11-27 12:28 +1100
Articles 4 — 4 participants

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


Contents

  Question about output different with command dis.dis(code) fl <rxjwg98@gmail.com> - 2015-11-26 01:02 -0800
    Re: Question about output different with command dis.dis(code) Random832 <random832@fastmail.com> - 2015-11-26 04:12 -0500
    Re: Question about output different with command dis.dis(code) Chris Angelico <rosuav@gmail.com> - 2015-11-26 20:09 +1100
    Re: Question about output different with command dis.dis(code) Steven D'Aprano <steve@pearwood.info> - 2015-11-27 12:28 +1100

#99546 — Question about output different with command dis.dis(code)

Fromfl <rxjwg98@gmail.com>
Date2015-11-26 01:02 -0800
SubjectQuestion about output different with command dis.dis(code)
Message-ID<f0dc1c2c-6fda-4bd8-a71b-29db358afe14@googlegroups.com>
Hi,

I see the following from a previous post:


Python 1.5.2 (#1, Aug 27 2012, 09:09:18)  [GCC 4.1.2 20080704 (Red Hat 
4.1.2-52)] on linux2 
Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam 
>>> import dis 
>>> code = compile("(1, 2, 3)", "", "eval") 
>>> dis.dis(code) 
          0 SET_LINENO          0 
          3 LOAD_CONST          0 (1) 
          6 LOAD_CONST          1 (2) 
          9 LOAD_CONST          2 (3) 
         12 BUILD_TUPLE         3 
         15 RETURN_VALUE 


When I run the above three line code, I get the following:

dis.dis(code)
  1           0 LOAD_CONST               3 ((1, 2, 3))
              3 RETURN_VALUE        


on my Windows 7 PC Canopy. Are there something, my input or Python difference
make the output different?

Thanks,

[toc] | [next] | [standalone]


#99547

FromRandom832 <random832@fastmail.com>
Date2015-11-26 04:12 -0500
Message-ID<mailman.125.1448529183.20593.python-list@python.org>
In reply to#99546
fl <rxjwg98@gmail.com> writes:
> Python 1.5.2 (#1, Aug 27 2012, 09:09:18)  [GCC 4.1.2 20080704 (Red Hat 
> 4.1.2-52)] on linux2

The context of the post was discussing the behavior of a
very old version of python. I'm not sure how you missed
this.

> When I run the above three line code, I get the following:

Further down in the same post you saw, he mentioned that
modern versions of python do this, and showed the same
output that you have.

[toc] | [prev] | [next] | [standalone]


#99548

FromChris Angelico <rosuav@gmail.com>
Date2015-11-26 20:09 +1100
Message-ID<mailman.126.1448529727.20593.python-list@python.org>
In reply to#99546
On Thu, Nov 26, 2015 at 8:02 PM, fl <rxjwg98@gmail.com> wrote:
> Are there something, my input or Python difference
> make the output different?

Anything involving the disassembly of Python code depends heavily on
internal interpreter details. You just quoted something showing that
ancient versions of Python did at run-time what current versions have
optimized to a compile-time construction (and thus the quick
LOAD_CONST instead of the full work of building the tuple). If you
switch to PyPy, Jython, IronPython, or some other implementation of
the language, the byte code may be completely different - or may not
be available at all. Using dis.dis is a great way of finding out what
is actually happening, but it's never something you can depend on the
stability of.

ChrisA

[toc] | [prev] | [next] | [standalone]


#99613

FromSteven D'Aprano <steve@pearwood.info>
Date2015-11-27 12:28 +1100
Message-ID<5657b1bf$0$1601$c3e8da3$5496439d@news.astraweb.com>
In reply to#99546
On Thu, 26 Nov 2015 08:02 pm, fl wrote:

> Hi,
> 
> I see the following from a previous post:
> 
> 
> Python 1.5.2 (#1, Aug 27 2012, 09:09:18)  [GCC 4.1.2 20080704 (Red Hat
> 4.1.2-52)] on linux2
> Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam
>>>> import dis
>>>> code = compile("(1, 2, 3)", "", "eval")
>>>> dis.dis(code)
>           0 SET_LINENO          0
>           3 LOAD_CONST          0 (1)
>           6 LOAD_CONST          1 (2)
>           9 LOAD_CONST          2 (3)
>          12 BUILD_TUPLE         3
>          15 RETURN_VALUE


This output is from Python 1.5, which is about 20 years old or so, and long
obsolete.


> When I run the above three line code, I get the following:
> 
> dis.dis(code)
>   1           0 LOAD_CONST               3 ((1, 2, 3))
>               3 RETURN_VALUE


This output is (probably) from Python 2.7, which is much more recent. The
byte-code compiler is much smarter now than in old versions of Python.


By the way, this is a really good question! I especially like the fact that
you tried running the code for yourself first.




-- 
Steven

[toc] | [prev] | [standalone]


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


csiph-web