Олеся Индычко, 201 группа, магистратура UniSize 14201 | Бельницкая Елизавета Алексеевна 321 UniSize 13398 | ||||
---|---|---|---|---|---|
n | 1 | class SizeDescriptor: | n | 1 | class Sizer: |
2 | 2 | ||||
n | 3 | def __get__(self, instance, owner): | n | 3 | def __get__(self, obj, cls): |
4 | if hasattr(instance, '__len__'): | 4 | if hasattr(obj, '__len__'): | ||
5 | return len(instance) | 5 | return len(obj) | ||
6 | elif hasattr(instance, '__abs__'): | 6 | elif hasattr(obj, '__abs__'): | ||
7 | return abs(instance) | 7 | return abs(obj) | ||
8 | else: | ||||
9 | return 0 | 8 | return 0 | ||
10 | 9 | ||||
11 | def sizer(cls): | 10 | def sizer(cls): | ||
t | 12 | cls.size = SizeDescriptor() | t | 11 | cls.size = Sizer() |
13 | return cls | 12 | return cls |
Legends | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
|