[Tutor] Should I subclass UserDict or dict?
Magnus Lyckå
magnus@thinkware.se
Fri May 9 23:02:02 2003
At 19:13 2003-05-09 -0700, Terry Carroll wrote:
>Should I inherit from the
>built-in dict class or from UserDict?
Use dict if you don't need to support Python versions < 2.2, and don't
plan to make the classes persistent with the ZOPE Object DataBase.
>On the only platform I plan to run this on, I run Python 2.2.2. I know
>that dict is only inheritable from starting in 2.2. Is 2.2 pervasive now
Yes, I think so.
>(my ISP's highest level of Python is 2.1.1, for example), or should I use
My ISP upgraded to 2.2 when I asked them. Have you asked?
(Don't forget to say please. :)
>UserDict to ensure compatibility? Is there really any big advantage of
>user the built-in dict instead of UserDict?
Performance should be better I assume, but please measure. I assume
the two classes will be very similar, so I guess you can test both
ways.
I can't see that this is a big decision though. Surely it's easy
to rewrite as inheriting UserDict if there turns out to be problems
using dict as a base class. This is after all Python. One of the
big advantages with Python is that you can test different versions
easily.
--
Magnus Lycka (It's really Lyckå), magnus@thinkware.se
Thinkware AB, Sweden, www.thinkware.se
I code Python ~ The shortest path from thought to working program