Calling Function Without Parentheses!

Terry Reedy tjreedy at
Sun Jan 2 21:52:04 EST 2005

"Kamilche" <klachemin at> wrote in message 
news:1104715584.407505.190910 at
> What a debug nightmare! I just spent HOURS running my script through
> the debugger, sprinkling in log statements, and the like, tracking down
> my problem.

Did you try PyChecker?  (Don't know if

> I called a function without the ending parentheses.

Which means you didn't call, and that was your problem ;-)  In Python, the 
(...) pair in the appropriate context (where an operator is expected) *is* 
the infix/postfix call operator.  It is equivalent to the call or gosub 
prefix in some other languages.  The call operator works with any callable, 
not just function objects.

>I sure do WISH Python would trap it when I try to do the following:

trap = raise an exception?  nooooh.

> MyFunc
> instead of:
> MyFunc()

In Python, non-keyword names resolve at runtime to the objects they are 
then bound to.  This simple, uniform rule is, to me, part of the beauty of 
Python.  There are lots of times that one wants to refer to a callable 
without calling it.  Indeed, because Python separates referring to an 
object from calling the object, it can and does have a broader notion of 
'callable' than other languages.  This includes the option of making 
instances of any user class callable (by including a __call__ method).

Terry J. Reedy

More information about the Python-list mailing list