On 18/11/2016 00:47, Steve D'Aprano wrote:
On Fri, 18 Nov 2016 12:19 am, BartC wrote:

On 17/11/2016 12:20, Steve D'Aprano wrote:

In the most recent versions of Python, dis.dis() will also accept a
string:

py> dis.dis('y = x + 1')
  1           0 LOAD_NAME                0 (x)
              3 LOAD_CONST               0 (1)
              6 BINARY_ADD
              7 STORE_NAME               1 (y)
             10 LOAD_CONST               1 (None)
             13 RETURN_VALUE


Py2 gave me (for "y=x+1"):

           0 SETUP_EXCEPT    30781 (to 30784)
           3 STORE_SLICE+3
           4 <49>

Py3.4 works as you say but after that result I was disinclined to take
it further!


You may have missed the bit where I said "In the most recent versions".
Python 2.7 will be interpreting the string "y=x+1" as compiled byte-code,
and disassembling it into junk.

I did my tests ('dis.dis("x=10")') before your post and before my original post. Py2 generated nonsense so I tried something else.

That Py2's dis.dis() accepts a string argument but treats it as compiled byte-code sounds like a bug. Unless it's a feature.

--
Bartc

--
https://mail.python.org/mailman/listinfo/python-list

Reply via email to