Re: Writing an immutable object in python

2005-10-20 Thread Magnus Lycka
Mapisto wrote: > Ok, I've understood my mistake. > > Now, my list contains a shared entry of an empty object. When an entry > is needed to be changed, I check if the entry is the shared empty > object; in that case I create a new unique instance. If the entry is > already a unique instance, I use

Re: Writing an immutable object in python

2005-10-20 Thread Magnus Lycka
Mapisto wrote: > Ok, I've understood my mistake. > > Now, my list contains a shared entry of an empty object. When an entry > is needed to be changed, I check if the entry is the shared empty > object; in that case I create a new unique instance. If the entry is > already a unique instance, I use

Re: Writing an immutable object in python

2005-10-18 Thread Mapisto
Ok, I've understood my mistake. Now, my list contains a shared entry of an empty object. When an entry is needed to be changed, I check if the entry is the shared empty object; in that case I create a new unique instance. If the entry is already a unique instance, I use it, so the empty object isn

Re: Writing an immutable object in python

2005-10-17 Thread Magnus Lycka
Mapisto wrote: > Hi, > > I've noticed that if I initialize list of integers in the next manner: > > my_list = [0] * 30 > > > It works just fine, even if I'll try to assign one element: > > id( my_list[4] ) > > 10900116 > id( my_list[6] ) > > 10900116 > my_list[4] = 6

Re: Writing an immutable object in python

2005-10-17 Thread Donn Cave
In article <[EMAIL PROTECTED]>, "Mapisto" <[EMAIL PROTECTED]> wrote: > I've noticed that if I initialize list of integers in the next manner: > > >>> my_list = [0] * 30 > > It works just fine, even if I'll try to assign one element: > > >>> id( my_list[4] ) > 10900116 > >>> id( my_list[6] ) >

Re: Writing an immutable object in python

2005-10-17 Thread Diez B. Roggisch
> The change in the poision occurs becouse int() is an immutable object. > > if I will do the same with a user-defined object, This reference > manipulating will not happen. So, every entry in the array will refer > to the same instance. > > Is there a way to bypass it (or perhaps to write a self

Writing an immutable object in python

2005-10-17 Thread Mapisto
Hi, I've noticed that if I initialize list of integers in the next manner: >>> my_list = [0] * 30 It works just fine, even if I'll try to assign one element: >>> id( my_list[4] ) 10900116 >>> id( my_list[6] ) 10900116 >>> my_list[4] = 6 >>> id( my_list[4] ) 10900044 >>> id( my_list[6] ) 1090011