__getitem__ and classmethod/staticmethod

Discussion in 'Python' started by Karl Chen, Jun 25, 2004.

  1. Karl Chen

    Karl Chen Guest

    Hi.

    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
    Karl Chen, Jun 25, 2004
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. KanZen

    __getitem__ and arguments

    KanZen, Jul 19, 2003, in forum: Python
    Replies:
    4
    Views:
    753
    Ben Finney
    Jul 19, 2003
  2. Andrew Bennetts

    Re: __getitem__ and classmethod/staticmethod

    Andrew Bennetts, Jun 25, 2004, in forum: Python
    Replies:
    0
    Views:
    479
    Andrew Bennetts
    Jun 25, 2004
  3. Steven Bethard

    unittest.TestCase, lambda and __getitem__

    Steven Bethard, Sep 13, 2004, in forum: Python
    Replies:
    7
    Views:
    446
    Alex Martelli
    Sep 14, 2004
  4. C Gillespie

    staticmethod and classmethod

    C Gillespie, May 24, 2005, in forum: Python
    Replies:
    5
    Views:
    5,759
    =?iso-8859-1?Q?Fran=E7ois?= Pinard
    May 26, 2005
  5. Bruno Desthuilliers

    classmethod & staticmethod

    Bruno Desthuilliers, Jul 21, 2007, in forum: Python
    Replies:
    16
    Views:
    610
    Steven D'Aprano
    Jul 26, 2007
Loading...

Share This Page