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
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
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
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',
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'):
>
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:
>>
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', '
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', '
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