ugly python namespace bug

Roy Smith roy at popmail.med.nyu.edu
Mon Dec 20 16:02:59 EST 1999


I had a function which use to look like this:

   for type in stuff:
      if type == default:
         etc...

It worked fine, but for one reason or another, I decided to change the variable 
name from type to option, but forgot to change it in one place, and ended up 
with:

   for option in stuff:
      if type == default:
         etc...

My code stopped working, with the equality test always failing.  I scratched my 
head a while until I found the problem, but then couldn't figure out why I 
didn't get a name error ("type" undefined) until a co-worker pointed out that 
type is a built-in function.  My first version of the code just over-wrote the 
default value of type!

I see how it all works now, but boy, stuff like this sure does invite all sorts 
of nasty debugging problems!

-- 
Roy Smith <roy at popmail.med.nyu.edu>
New York University School of Medicine




More information about the Python-list mailing list