opening a file opens it in Notepad

Alex Martelli aleax at aleax.it
Thu Feb 6 09:03:59 EST 2003


Peter Hansen wrote:
   ...
> I suspect there is lots and lots of code out there that innocently
> uses variables named "input" or maybe "map", "hash", or "id" and

Oh yes.

> I doubt that many problems result.

You may not have taught many beginners, perhaps.  In my experience,
there IS a substantial amount of time wasted because a beginner
tries some nice construct he's been suggested or has read about
and gets weird errors -- because he or she has unwittingly bound
in some previous part of his or her code some built-in name that 
is used in the construct in question -- and a lesser but (I'd guess)
still nontrivial amount of time similarly wasted by non-beginners.

Some builtin names (those you might be better advised to never
or VERY seldom use, like 'input') may be less troublesome than
others in this respect, of course.  Perhaps the worst are the
name of popular types -- file, list, dict, tuple, int... -- too
frequently rebound to mean "this here file", "yonder list" and
so on, yet at the same time frequently needed on their own.

It's a good thing that all of these are non-callable, since the
typical use of a typename is calling it; so, the TypeError gets
raised pretty soon.  Still, if PyChecker could warn about such
rebindings, it wouldn't be a bad thing, I believe.


> But you're right that it is probably a good thing to learn to avoid...

So it's not a bad idea to keep reminding beginners not to do it...
without overstating one's case, of course.


Alex





More information about the Python-list mailing list