sharing data in list sub-classes

Terry Reedy tjreedy at udel.edu
Tue Jun 4 11:37:51 EDT 2002


"Sergei Barbarash" <sgt at outline.ru> wrote in message
news:87znybyzsg.fsf at zaraza.fep.ru...
> Hello,
>
> Is there a way to share list data in classes that inherit the "list"
class?
>
> Example:
>
> ,----
> | class A(list):
> |     <what should I put here?>
> |
> | mem = [1,2,3,4,5]
> |
> | a1 = A(mem)
> | a2 = A(mem)

Try a2 = a1 instead

> |
> | a1[0] = 1024
> | if a2[0] == 1024:
> |     print "Everything's fine"
> `----
>
> With obsolete UserList module it works fine, because it stores the
data in
> self.data variable. Is there a "right" 2.2-ish way to do the same
thing?
>
> Thanks,
> --
> Sergei







More information about the Python-list mailing list