5 ms·
Sorry. That's something that was true in 2.x but not anymore. There used to be UserString, UserList, UserDict classes for serving as base classes. We still have
by rbanffy 6y ago
Sorry. That's something that was true in 2.x but not anymore. There used to be UserString, UserList, UserDict classes for serving as base classes. We still have those, but, at least now, we can extend the fundamental classes directly.
They are a bit more convenient than the built-ins.
- pansa2 6y agoWe can inherit from `list`, `dict` etc., but objects of those classes are still not as flexible as "normal" objects. For example, we can't add an attribute to a list using `l = []; l.a = 1`.
- joshuamorton 6y agoI believe that makes them the same as any other class defined with `__slots__`: >>> class Foo: ... __slots__ = ('a', 'b') ... >>> f = Foo() >>> f.a = 1 >>> f.b = 2 >>> f.c = 3 Traceback (most recent call last): File "<stdin>", line 1, in <module> AttributeError: 'Foo' object has no attribute 'c'