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

Steven D'Aprano steve at pearwood.info
Thu Nov 26 20:28:29 EST 2015


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




More information about the Python-list mailing list