<html>
<body>
At 12:33 PM 4/7/2008, Kent Johnson wrote:<br>
<blockquote type=cite class=cite cite="">In [13]: import dis<br>
In [15]: def foo():<br>
....: a = 10<br>
In [16]: dis.dis(foo)<br>
2 0
LOAD_CONST
1 (10)<br>
3
STORE_FAST
0 (a)<br>
6
LOAD_CONST
0 (None)<br>
9 RETURN_VALUE<br><br>
The STORE_FAST instruction is storing the (reference to) the value 10 at
<br>
offset 0 in the local storage section of the stack
frame.</blockquote><br>
I looked up "offset" in Wikipedia:<br><br>
====================================================<br>
Offset (computer science)<br><br>
This article describes the computer science term. <br><br>
In computer science, an offset within an array or other data structure
object is an integer indicating the distance (displacement) from the
beginning of the object up until a given element or point, presumably
within the same object. The concept of a distance is valid only if all
elements of the object are the same size (typically given in bytes or
words).<br><br>
In computer engineering and low-level programming (such as assembly
language), an offset usually denotes the number of address locations
added to a base address in order to get to a specific absolute address.
In this meaning of offset, only the basic address unit, usually the 8-bit
byte, is used to specify the offset's size. In this context an offset is
sometimes called a relative address.<br><br>
For example, given an array of characters A, containing abcdef, one can
say that the element containing the letter 'c' has an offset of 2 from
the start of A.<br><br>
Retrieved from
"<a href="http://en.wikipedia.org/wiki/Offset_(computer_science)" eudora="autourl">
http://en.wikipedia.org/wiki/Offset_%28computer_science%29</a>"<br>
===========================================================<br><br>
This may be pushing it with you, but I found the dis.dis() thing
fascinating. Here's a bit more complex function.<br><br>
<tt>def f(x):<br>
if x%2:<br>
return
"odd"<br>
else:<br>
return
"even"<br><br>
</tt>Could you give a blow-by-blow on the dis.dis()?<br><br>
=======================================<br>
<tt>In [21]: import dis<br>
....:<br>
Out[21]: <module 'dis' from 'E:\Python25\lib\dis.pyc'><br><br>
In [22]: def f(x):<br>
....: if x%2:<br>
....: return
"odd"<br>
....: else:<br>
....: return
"even"<br>
....:<br>
....:<br><br>
In [23]: dis.dis(f)<br>
2 0
LOAD_FAST
0 (x)<br>
3
LOAD_CONST
1 (2)<br>
6 BINARY_MODULO<br>
7
JUMP_IF_FALSE
8 (to 18)<br>
10 POP_TOP<br><br>
3 11
LOAD_CONST
2 ('odd')<br>
14 RETURN_VALUE<br>
15
JUMP_FORWARD
5 (to 23)<br>
>> 18
POP_TOP<br><br>
5 19
LOAD_CONST
3 ('even')<br>
22 RETURN_VALUE<br>
>> 23
LOAD_CONST
0 (None)<br>
26 RETURN_VALUE<br>
</tt>=========================================<br><br>
Thanks,<br><br>
Dick Moores<br><br>
<br>
<x-sigsep><p></x-sigsep>
================================<br>
UliPad <<The Python Editor>>:
<a href="http://code.google.com/p/ulipad/" eudora="autourl">
http://code.google.com/p/ulipad/</a></body>
</html>