- Trying to create a dynamic class property, however, when called on instances an error is thrown. And when called on the class, an unknown object is returned.
I believe the issue is with the understanding of how classmethod is defined.
class Warehouse:
def __init__(self, inventory_count):
self.inventory_count = inventory_count
class Shop:
warehouse = Warehouse(5)
@property
@classmethod
def iv_count(cls):
return cls.warehouse.inventory_count
s = Shop()
print s.iv_count
Error message:
Traceback (most recent call last):
File "main.py", line 15, in <module>
print s.iv_count
TypeError: 'classmethod' object is not callable
Info:
print Shop.iv_count # <property object at 0x7f5f880d12b8>
- Where can I find the source code for python functions,
staticmethod
and similarlyclassmethod
?