Paddy wrote: > And the ellipses ... ? ;)
py> class Bob(dict): ... def __getitem__(self, k, *args, **kwargs): ... if k is Ellipsis: ... return sorted(self.keys()) ... else: ... return dict.__getitem__(self, k, *args, **kwargs) ... def __setitem__(self, k, *args, **kwargs): ... if k is Ellipsis: ... raise KeyError, "Can't make elliptical assignments." ... else: ... return dict.__setitem__(self, k, *args, **kwargs) ... py> b = Bob(a=1, b=2, c=3, d=15.5) py> b {'a': 1, 'b': 2, 'c': 3, 'd': 15.5} py> for k in b[...]: print '%s ==> %s' % (k, b[k]) ... a ==> 1 b ==> 2 c ==> 3 d ==> 15.5 py> b[...] = 2 ------------------------------------------------------------ Traceback (most recent call last): File "<ipython console>", line 1, in <module> File "<ipython console>", line 9, in __setitem__ <type 'exceptions.KeyError'>: "Can't make elliptical assignments." -- http://mail.python.org/mailman/listinfo/python-list