At 02:57 PM 4/7/2008, Dick Moores wrote:

This may be pushing it with you, but I found the dis.dis() thing fascinating. Here's a bit more complex function.

 def f(x):
     if x%2:
         return "odd"
     else:
         return "even"

Could you give a blow-by-blow on the dis.dis()?

=======================================
In [21]: import dis
   ....:
Out[21]: <module 'dis' from 'E:\Python25\lib\dis.pyc'>

In [22]: def f(x):
   ....:     if x%2:
   ....:         return "odd"
   ....:     else:
   ....:         return "even"
   ....:
   ....:

In [23]: dis.dis(f)
  2           0 LOAD_FAST                0 (x)
              3 LOAD_CONST               1 (2)
              6 BINARY_MODULO
              7 JUMP_IF_FALSE            8 (to 18)
             10 POP_TOP

  3          11 LOAD_CONST               2 ('odd')
             14 RETURN_VALUE
             15 JUMP_FORWARD             5 (to 23)
        >>   18 POP_TOP

  5          19 LOAD_CONST               3 ('even')
             22 RETURN_VALUE
        >>   23 LOAD_CONST               0 (None)
             26 RETURN_VALUE
=========================================

Kent, never mind. I just realized that all those LOAD_FAST's, etc., are defined in http://docs.python.org/lib/bytecodes.html .

Of course, should you want to say something, I'm always ready to listen to you.

And that goes for Alan as well..

Dick

           ================================
UliPad <<The Python Editor>>: http://code.google.com/p/ulipad/

_______________________________________________
Tutor maillist  -  [email protected]
http://mail.python.org/mailman/listinfo/tutor

Reply via email to