This question is regarding subclassing built-in data types
in Python; for example:
class MyList(list):
def __init__(self, *args):
super().__init__()
class MyDict(dict):
def __init__(self, *args):
super().__init__()
my_list = MyList()
my_dict = MyDict()
Note : This is just an example; my question is for any built-in data types
in general, not just list
and dict
data-types.
pros
and cons
of subclassing built-in data types like this?super()
when subclassing built-in data types like this?list
and dict
built-in data subclass?My advise is to use UserDict
and UserList
from collections
module as starting point:
UserDict
: https://docs.python.org/3/library/collections.html#userdict-objects
UserList
: https://docs.python.org/3/library/collections.html#userlist-objects
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.