Say I have a simple object:
class Providers:
Apple = "Apple"
Banana = "Banana"
Cherries = "Seedless Cherries"
I'd like to be able to do something like if "Apple" in Providers..
, which I believe requires me to set two magic methods, __len__
and __getitem__
.
I tried something as simple as
@classmethod
def __len__(cls):
return 3
but when I run len(Providers)
I get TypeError: object of type 'type' has no len()
but Providers.__len__()
returns 3.
How can I get the len
of a class without instantiating it? Or do they need to always be instantiated with __init__
and self.Apple = 'Apple'?