Calling Function Without Parentheses!
Jeff Shannon
jeff at ccvcorp.com
Fri Jan 7 15:53:34 EST 2005
Kamilche wrote:
> Yeah, but still. If they even had the most basic check, like 'an object
> is being referred to on this line, but you're not doing anything with
> it' would be handy in catching that. When you use an object like that,
> usually you're doing something with it, like assigning it to a variable.
>
In many cases, however, it's not possible to distinguish this.
def get_pi():
import math
return math.pi
print my_func(get_pi)
Now, am I trying to pass the function object get_pi into my_func(), or
do I want to call get_pi() and pass the return value?
There are also many times when it's sensible to do nothing with an
object reference -- i.e. ignoring the return value of a function which
you're calling for its side-effects.
It seems to me that it's reasonable for the Python interpreter to
*not* attempt to guess at whether a questionable usage is an error or
not. Better to have that done by a developer tool (pychecker) than
through runtime checks every time the program is used.
Jeff Shannon
Technician/Programmer
Credit International
More information about the Python-list
mailing list