What exactly is a python variable?

BartC bc at freeuk.com
Thu Nov 17 08:19:27 EST 2016


On 17/11/2016 12:20, Steve D'Aprano wrote:
> On Thu, 17 Nov 2016 10:37 pm, BartC wrote:

>> (I don't know how to disassemble code outside a function, not from
>> inside the same program. Outside it might be: 'python -m dis file.py')

> 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!

-- 
Bartc



More information about the Python-list mailing list