Mike Meyer wrote:
Actually, UserList and UserDict are just wrappers around the builtin
types. So the performance hit is one Python function call - pretty
much neglible. But new code should still subclass the builtins.
Interesting that they're not fully compatible with the builtins:
>>> dict(dict=35)
{'dict': 35}
>>> UserDict.UserDict(dict=35)
Traceback (most recent call last):
File "<interactive input>", line 1, in ?
File "C:\Program Files\Python\lib\UserDict.py", line 7, in __init__
self.update(dict)
File "C:\Program Files\Python\lib\UserDict.py", line 46, in update
self.data.update(dict)
TypeError: iteration over non-sequence
>>> dict(self=[1, 2, 3])
{'self': [1, 2, 3]}
>>> UserDict.UserDict(self=[1, 2, 3])
Traceback (most recent call last):
File "<interactive input>", line 1, in ?
TypeError: __init__() got multiple values for keyword argument 'self'
I wonder why UserDict.UserDict's __init__ and update aren't written like:
def __init__(*args, **kwds):
self, args = args[0], args[1:]
...
'Course I never use these, so I guess what am I complaining about? ;)
Steve
--
http://mail.python.org/mailman/listinfo/python-list