locks
Duncan Booth
duncan.booth at invalid.invalid
Wed Oct 13 10:03:37 EDT 2004
Cliff Wells wrote:
> I'm no expert at dis nor Python bytecode, but I'll give it a shot :)
>
>>>> l = []
>>>> dis.dis(l.append(1))
> 134 0 LOAD_GLOBAL 0 (findlabels)
> 3 LOAD_FAST 0 (code)
> 6 CALL_FUNCTION 1
> 9 STORE_FAST 5 (labels)
>
>
> ...
><snip dis spitting out over 500 lines of bytecode>
> ...
>
> 172 >> 503 PRINT_NEWLINE
> 504 JUMP_ABSOLUTE 33
> >> 507 POP_TOP
> 508 POP_BLOCK
> >> 509 LOAD_CONST 0 (None)
> 512 RETURN_VALUE
>>>>
>
>
> It looks fairly non-atomic to me.
The append method of a list returns None. dis.dis(None) disassembles the
code from the last traceback object, nothing at all to do with your
l.append(1) code.
Try this instead:
>>> def f():
l.append(1)
>>> dis.dis(f)
2 0 LOAD_GLOBAL 0 (l)
3 LOAD_ATTR 1 (append)
6 LOAD_CONST 1 (1)
9 CALL_FUNCTION 1
12 POP_TOP
13 LOAD_CONST 0 (None)
16 RETURN_VALUE
More information about the Python-list
mailing list