You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
21 lines
365 B
21 lines
365 B
2 years ago
|
def implicit_int(cls):
|
||
|
def wrapper(self, item):
|
||
|
if hasattr(object, item):
|
||
|
return object.__getattr__(self, attr)
|
||
|
else:
|
||
|
return 0
|
||
|
cls.__getattr__ = wrapper
|
||
|
return cls
|
||
|
|
||
|
'''Тесты'''
|
||
|
|
||
|
@implicit_int
|
||
|
class A:
|
||
|
x = -1
|
||
|
|
||
|
a = A()
|
||
|
print(a)
|
||
|
print(a.x)
|
||
|
print(a.e)
|
||
|
print(a.e + 589) # Вывод: 589
|