skyworld writes:

> Hi,
> 
> I see someone's code as this:
> 
> class ABC: ....
>     def __init__(self, env):
>          .......
>          self.jmpTable['batchQ']['submit_job']  = self.lsf_submit
>          .......
>     def lsf_submit(self, cmd,env):
>          .....
> 
> what confused me is why there is no parentheses for self.lsf_submit in
> "self.jmpTable['batchQ']['submit_job']  = self.lsf_submit"? what does
> this piece of code mean? thanks.

Functions are objects. The above is storing the function lsf_submit in
a dict from where it can later be taken and invoked. The invocation is
indicated by the parentheses after an expression that denotes a
function.

Consider the following, and play with examples of your own in a Python
interpreter.

   >>> from math import acos
   >>> def foo(x): return acos, x
   ... 
   >>> foo(-1)
   (<built-in function acos>, -1)
   >>> foo(-1)[0]
   <built-in function acos>
   >>> foo(-1)[0](foo(-1)[1])
   3.141592653589793

Or simply:

   >>> acos
   <built-in function acos>
   >>> acos(-1)
   3.141592653589793
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to