Re: understanding list scope

2008-09-22 Thread Tino Wildenhain
Hi, Alex wrote: Hi all! I have a problem understanding the behaviour of this snippet: data_set = ({"param":"a"},{"param":"b"},{"param":"c"}) for i in range(len(data_set)): ds = data_set[:] data = ds[i] if i == 1: data['param'] = "y" if i == 2: data['param'] = "x" print da

Re: understanding list scope

2008-09-22 Thread mbezzi
On Sep 21, 7:48 pm, Peter Pearson <[EMAIL PROTECTED]> wrote: > FWIW, since I started following this newsgroup, I've noticed > that I no longer have those crises that revolve around the depth > of a copy.  I conjecture that they resulted from non-pythonic > style.  Try following this newsgroup for

Re: understanding list scope

2008-09-21 Thread Peter Pearson
On Sun, 21 Sep 2008 06:17:36 -0700 (PDT), Alex wrote: > On 21 Set, 15:07, George Sakkis <[EMAIL PROTECTED]> wrote: >> On Sep 21, 8:51 am, Alex <[EMAIL PROTECTED]> wrote: [snip] >> > I have a problem understanding the behaviour of this snippet: [snip] >> Because you're doing a shallow copy: >> http:

Re: understanding list scope

2008-09-21 Thread Alex
On 21 Set, 15:07, George Sakkis <[EMAIL PROTECTED]> wrote: > On Sep 21, 8:51 am, Alex <[EMAIL PROTECTED]> wrote: > > > > > Hi all! > > > I have a problem understanding the behaviour of this snippet: > > > data_set = ({"param":"a"},{"param":"b"},{"param":"c"}) > > > for i in range(len(data_set)): >

Re: understanding list scope

2008-09-21 Thread alex23
On Sep 21, 10:51 pm, Alex <[EMAIL PROTECTED]> wrote: > Why? I'm coping data_set in ds so why data_set is changed? You're making a copy of the ds tuple, which has the -same- contents as the original. To create copies of the contents as well, try the deepcopy function from the copy module. As an as

Re: understanding list scope

2008-09-21 Thread George Sakkis
On Sep 21, 8:51 am, Alex <[EMAIL PROTECTED]> wrote: > Hi all! > > I have a problem understanding the behaviour of this snippet: > > data_set = ({"param":"a"},{"param":"b"},{"param":"c"}) > > for i in range(len(data_set)): >     ds = data_set[:] >     data = ds[i] >     if i == 1: data['param'] = "y