__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. Advertisements

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:
    946
    Ben Finney
    Jul 19, 2003
  2. Steven Bethard

    unittest.TestCase, lambda and __getitem__

    Steven Bethard, Sep 13, 2004, in forum: Python
    Replies:
    7
    Views:
    588
    Alex Martelli
    Sep 14, 2004
  3. Zak Arntson

    GUI Frames and classmethod

    Zak Arntson, Dec 3, 2004, in forum: Python
    Replies:
    6
    Views:
    469
    Jeremy Bowers
    Dec 7, 2004
  4. C Gillespie

    staticmethod and classmethod

    C Gillespie, May 24, 2005, in forum: Python
    Replies:
    5
    Views:
    5,882
    =?iso-8859-1?Q?Fran=E7ois?= Pinard
    May 26, 2005
  5. Replies:
    3
    Views:
    468
    Xavier Morel
    Feb 3, 2006
  6. WaterWalk
    Replies:
    2
    Views:
    409
    Gabriel Genellina
    Dec 12, 2006
  7. Bruno Desthuilliers

    classmethod & staticmethod

    Bruno Desthuilliers, Jul 21, 2007, in forum: Python
    Replies:
    16
    Views:
    707
    Steven D'Aprano
    Jul 26, 2007
  8. timh
    Replies:
    6
    Views:
    431
    Dave Angel
    May 18, 2009
Loading...