> Aha, that's useful to know. So it's a no-no to subclass *any* builtin?

I don't think it's a no-no, I just think it comes with a few problems that are 
solved if you subclass the classes that are *meant* to be subclassed, like 
UserDict, UserList, or UserString.

> I checked collections.UserDict and it indeed looks promising. Caveat: it;s 
> Python 3 only (not sure what versionit was introduced).

It's in both Python 2 and 3, but they're not in the same module. That's why I 
used the following construct to import it. In both cases, UserDict is imported 
correctly and the module where it came from does not matter.

try:
    from collections import UserDict
except ImportError:
    from UserDict import UserDict

Here are the docs:

- Python 2: https://docs.python.org/2/library/userdict.html
- Python 3: 
https://docs.python.org/3/library/collections.html#collections.UserDict

Regards,
   Alex
_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor

Reply via email to