__getitem__ and classmethod/staticmethod

K

Karl Chen

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,577
Members
45,052
Latest member
LucyCarper

Latest Threads

Top