Calling Function Without Parentheses!

Dan Bishop danb_83 at yahoo.com
Mon Jan 3 03:10:15 CET 2005


Kamilche wrote:
> 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.
>
> I called a function without the ending parentheses. I sure do WISH
> Python would trap it when I try to do the following:
> MyFunc
>
> instead of:
>
> MyFunc()

You're a former Pascal programmer, aren't you? ;-)

In Python, it's not an error, because you can do things like:

>>> def simpson(f, a, b):
...    "Simpson's Rule approximation of the integral of f on [a, b]."
...    return (b - a) * (f(a) + 4 * f((a + b) / 2.0) + f(b)) / 6.0
...
>>> simpson(math.sin, 0.0, math.pi) # Note that math.sin is a function
2.0943951023931953




More information about the Python-list mailing list