It is the difference between calling a callable object to get its return value, vs passing a reference to the object. You call a function by doing: aFunc() But aFunc is an object which can be passed around. So if you pass aFunc to something else, then that target has a reference to the same callable. This is how "callbacks" work. You don't want to execute the function at that moment in time. You just want to pass a reference to it, so that at a later point in time the function can be called by a different owner.
For more detailed information, you can look at the __call__() special method of objects: https://docs.python.org/2/reference/datamodel.html#object.__call__ This is what defines the behavior for when you do aFunc() on the object aFunc Consider this: def f(): print "hello" f()# hello f.__call__()# hello On Fri, Jul 18, 2014 at 9:51 PM, Gabriele Bartoli <[email protected]> wrote: > Thanks man, I appreciate the feedback. > > Needless to say that I'm not working only on a test script, but I have > something else up my sleeve. Would you like to give it a try when I am done > with it? > > Cheers > > P.S. I'm still trying to understand why i have to remove the empty > parentheses when calling the callable function. I've been looking around > the internet but I can't find an answer. :( > > To make it clearer, why > > command = my_function > > > instead of > > command = my_function() > > I think I am missing something syntax-wise. > > > On Thursday, 17 July 2014 21:57:17 UTC+2, Justin Israel wrote: > >> Definitely not the first one. Avoid relying on globals when possible. >> The second and third are equally fine right now. But if you start needing >> more state such as storing more widgets or values, then the class will end >> up becoming the better choice. >> >>> >>> -- > You received this message because you are subscribed to the Google Groups > "Python Programming for Autodesk Maya" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To view this discussion on the web visit > https://groups.google.com/d/msgid/python_inside_maya/630eee2f-b4db-4c0c-a164-2bf33bfa7ad7%40googlegroups.com > <https://groups.google.com/d/msgid/python_inside_maya/630eee2f-b4db-4c0c-a164-2bf33bfa7ad7%40googlegroups.com?utm_medium=email&utm_source=footer> > . > > For more options, visit https://groups.google.com/d/optout. > -- You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAPGFgA3yKqtzdyaea95TgdhzMKjktvnMRcbkcisdeR%2BChrYUTg%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.
