Re: Closure/binding problem or misunderstanding

2007-11-09 Thread [EMAIL PROTECTED]
On Nov 9, 9:54 am, Boris Borcic <[EMAIL PROTECTED]> wrote: > Yes this is the expected behavior. Both your getpath() functions return the > current value of the single path variable at the time of invocation. Perhaps > this would be the slightest bit clearer if subdir.iteritems() did not provide >

Re: Closure/binding problem or misunderstanding

2007-11-09 Thread [EMAIL PROTECTED]
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 getpat

Re: Closure/binding problem or misunderstanding

2007-11-09 Thread Boris Borcic
[EMAIL PROTECTED] wrote: > If I run the following code: > > class path(object): > def __init__(self, **subdirs): > for name, path in subdirs.iteritems(): > def getpath(): > return path > setattr(self, name, getpath) > > export = path( > one

Re: Closure/binding problem or misunderstanding

2007-11-09 Thread Paul Hankin
On Nov 9, 2:32 pm, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote: > If I run the following code: > > class path(object): > def __init__(self, **subdirs): > for name, path in subdirs.iteritems(): > def getpath(): > return path > setattr(self, name,

Closure/binding problem or misunderstanding

2007-11-09 Thread [EMAIL PROTECTED]
If I run the following code: class path(object): def __init__(self, **subdirs): for name, path in subdirs.iteritems(): def getpath(): return path setattr(self, name, getpath) export = path( one = 'this is one', two = 'this is two', ) pr