How to avoid "f.close" (no parens) bug?

Dang Griffith noemail at
Thu Feb 12 17:48:03 CET 2004

On Thu, 12 Feb 2004 08:55:10 -0500, Peter Hansen <peter at>

>Stephen Ferg wrote:
>> I've just spent several very frustrating hours tracking down a bug in
>> one of my programs.  The problem was that I was writing text to a
>> file, and when I was done I coded
>>    f.close
>> when I should have been coding
>>    f.close()
>> with the parentheses.
>Would I be write in guessing that you have used VisualBASIC a lot
>in the past?  Or perhaps a similar language which allows the type
>of function call you would expect with the first form above?
>I believe f.close could be a legal call in VB (am I right?) and 
>I'm guessing that is the reason you are making this mistake.
>I doubt it's a common problem for many people, but maybe it is for
>those with a particular background.
    Pascal, Delphi also use this convention.  Personally, I think that
design for a language is strange, but if the language doesn't support
a "pointer to function" or "function" type, there's no ambiguosity to
the compiler.  A casual reader of the code can get confused, not
knowing if the code is referring to a function that returns a value,
or a simple attribute.  Delphi complicates it further by having
"attributes", which are sort of like a getter/setter used
(syntactically) as if it were an attribute assignment/reference.
    Point being it's not just VisualBasic (and Access and VBA).  I
think it's not unreasonable that your thought about someone's
background is relevant.  I'm from a C background, and never made this
particular mistake.

More information about the Python-list mailing list