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

John Roth newsgroups at jhrothjr.com
Wed Feb 11 16:10:29 EST 2004


"Stephen Ferg" <steve at ferg.org> wrote in message
news:b16e4ef7.0402110701.5acf67e4 at posting.google.com...
> 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.
>
> Although I love Python dearly, the fact that such an easy-to-make
> mistake should do nothing useful and do it silently (which, in this
> context, means: fail silently) seems to me a bit of a wart.
>
> In any event, does anybody have any suggestions for how a coder could
> avoid making such a mistake, or detect it quickly?
>
> I teach the occasional beginning Python class, and I would hate to
> have to tell my beginning students to watch out for making this kind
> of mistake because it can bite you in a most nasty way.

I don't know about anyone else, but I'd appreciate a run
time error message when it detects an impossible operation
on a function/bound method/unbound method which has no /
one operand on the top of the stack.

Something simple, like: "Unsupported operation on {function
| unbound method | bound method} with {no | one} operand
detected. Did you forget the empty calling parameter list < () >?"

So far, that would have saved me close to a cumulative
person-week of work!

John Roth





More information about the Python-list mailing list