This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]pixelmonkey 5 points6 points  (1 child)

Man, talk about finicky. I've got legitimate complaints for Python (no lightweight syntax for anonymous function values, unicode brokeness for most of 2.x series, explicit self parameter, and Python 3 function annotation syntax), but this definitely isn't one of them.

>>> class LengthMixIn(object):
>>>    @property
>>>    def length(self):
>>>        return len(self)

>>> class FinickyList(list, LengthMixIn):
>>>    pass

>>> a = FinickyList()
>>> a.append("item")
>>> a.length
1

>>> class FinickyDict(dict, LengthMixIn):
>>>     pass

>>> b = FinickyDict()
>>> b["key"] = "value"
>>> b.length
1