Re: namespace hacking question

2010-10-04 Thread Steve Howell
On Sep 30, 10:07 am, kj wrote: > This is a recurrent situation: I want to initialize a whole bunch > of local variables in a uniform way, but after initialization, I > need to do different things with the various variables. > I'm curious what a typical use case for this is. It seems funny to hav

Re: namespace hacking question

2010-10-04 Thread Lawrence D'Oliveiro
In message , MRAB wrote: > An alternative is to create a namespace in an instance of a class and > then add attributes to it: > > class Namespace(object): > pass > > n = Namespace() > for v in ('spam', 'ham', 'eggs'): > setattr(n, v, init(v)) > > foo(n.spam) > bar(n.ham) > baz(n.eggs

Re: namespace hacking question

2010-10-01 Thread bruno.desthuilli...@gmail.com
On 1 oct, 14:12, Fuzzyman wrote: > On Sep 30, 6:07 pm, kj wrote: > > > > > This is a recurrent situation: I want to initialize a whole bunch > > of local variables in a uniform way, but after initialization, I > > need to do different things with the various variables. > > > What I end up doing i

Re: namespace hacking question

2010-10-01 Thread Fuzzyman
On Sep 30, 6:07 pm, kj wrote: > This is a recurrent situation: I want to initialize a whole bunch > of local variables in a uniform way, but after initialization, I > need to do different things with the various variables. > > What I end up doing is using a dict: > > d = dict() > for v in ('spam',

Re: namespace hacking question

2010-09-30 Thread alex23
kj wrote: > This is a recurrent situation: I want to initialize a whole bunch > of local variables in a uniform way, but after initialization, I > need to do different things with the various variables. > > What I end up doing is using a dict: > > d = dict() > for v in ('spam', 'ham', 'eggs'): >  

Re: namespace hacking question

2010-09-30 Thread Arnaud Delobelle
MRAB writes: > On 30/09/2010 18:07, kj wrote: >> >> >> >> This is a recurrent situation: I want to initialize a whole bunch >> of local variables in a uniform way, but after initialization, I >> need to do different things with the various variables. >> >> What I end up doing is using a dict: >>

Re: namespace hacking question

2010-09-30 Thread MRAB
On 30/09/2010 18:07, kj wrote: This is a recurrent situation: I want to initialize a whole bunch of local variables in a uniform way, but after initialization, I need to do different things with the various variables. What I end up doing is using a dict: d = dict() for v in ('spam', 'ham', '

Re: namespace hacking question

2010-09-30 Thread bruno.desthuilli...@gmail.com
On 30 sep, 19:07, kj wrote: > This is a recurrent situation: I want to initialize a whole bunch > of local variables in a uniform way, but after initialization, I > need to do different things with the various variables. > > What I end up doing is using a dict: > > d = dict() > for v in ('spam', '

namespace hacking question

2010-09-30 Thread kj
This is a recurrent situation: I want to initialize a whole bunch of local variables in a uniform way, but after initialization, I need to do different things with the various variables. What I end up doing is using a dict: d = dict() for v in ('spam', 'ham', 'eggs'): d[v] = init(v) foo(d