Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

forgetting () after function

1 view
Skip to first unread message

Kia A. Arab

unread,
Mar 13, 2000, 3:00:00 AM3/13/00
to

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. 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?

--
____________________________________________________________________________

Kia A. Arab, Software Test Engineer
Space Telescope Science Institute
Engineering & Software Services Division/Software Testing Team
EMAIL: ka...@stsci.edu PHONE: 410-516-8597

Michal Bozon

unread,
Mar 13, 2000, 3:00:00 AM3/13/00
to
>
> 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. 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?
>

If you have a function without arguments, e.g. f(), and you type:
>>> g = f
it means, that g is not a result of function f, but it is also a function.
So you can type
>>> v = g()
this is same as
>>> v = f()

Michal Bozon
Faculty of Science, Charles Univ., Prague, Czech Rep.
bo...@natur.cuni.cz
http://www.natur.cuni.cz/~bozon


Justin Sheehy

unread,
Mar 13, 2000, 3:00:00 AM3/13/00
to pytho...@python.org
"Kia A. Arab" <ka...@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


0 new messages