forgetting () after function

Justin Sheehy dworkin at ccs.neu.edu
Mon Mar 13 13:57:52 EST 2000


"Kia A. Arab" <karab at stsci.edu> writes:

> I've noticed that if you inadvertantly omit the () at the end of a
> function call (that does not need params), python just ignores it, no
> warning, no nothing.

That is not exactly true.  If you have a function 'spam', then 

spam() 
 -> evaluates to the value returned by the function 
    (executes the function to get this value, of course)
spam
 -> evaluates to the function itself

This is intentional and useful.  Functions are first-class objects in Python.

> Does anyone know of a way to catch this somehow to avoid insidious
> logic errors that could result, or protect your program from blowing
> up down the line?

Test your programs?

Seriously, I can't think of much you can directly do to 'catch this',
since people may use this part of the language correctly and intentionally.

-Justin

 




More information about the Python-list mailing list