On Nov 9, 9:49 am, Paul Hankin <[EMAIL PROTECTED]> wrote: > It's behaving as defined though, and the usual work-around is to add a > variable with a default value. > > class path(object): > def __init__(self, **subdirs): > for name, path in subdirs.iteritems(): > def getpath(path=path): > return path > setattr(self, name, getpath) >
Thanks, Paul. That's helpful. I will re-read the reference manual, and see if I can find out where this behavior is defined. It looks like it's binding both locals and globals, but not actually taking a snapshot in time, as would, say Perl (I think). From an efficiency POV this makes great sense, and I can see that you get everything you need by essentially creating the closure yourself (by putting everything in the local space for the function). Bob -- http://mail.python.org/mailman/listinfo/python-list