__getitem__ and classmethod/staticmethod

Karl Chen quarl at nospam.quarl.org
Fri Jun 25 19:18:53 CEST 2004


Is it possible to make a classmethod out of __getitem__?

I.e. I want to do:

class C:
    def __getitem__(p):
        return 1+p

    __getitem__ = classmethod(__getitem__)

So that C[3] works (in addition to C()[3]).  But I always get 
    TypeError: unsubscriptable object

Karl 2004-06-25 10:14

More information about the Python-list mailing list