Pretty sure that this is not possible with a subclass list. This is possible with a subclass (just in Python ): collections.UserListUserList2
from collections import UserList
class MyList(UserList):
def __init__(self, it=None):
if isinstance(it, list):
self.data = it
else:
super().__init__(it)
def my_func(self):
return self
, UserList data , , it :
, :
l1 = list(range(10))
l2 = MyList(l1)
print(l1, l2, sep='\n')
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
:
l1[3] = -5
data, l1, , :
print(l1, l2, sep='\n')
[0, 1, 2, -5, 4, 5, 6, 7, 8, 9]
[0, 1, 2, -5, 4, 5, 6, 7, 8, 9]