-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.py
More file actions
75 lines (49 loc) · 1.4 KB
/
Copy pathtest.py
File metadata and controls
75 lines (49 loc) · 1.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
from datetime import datetime
import time
class SuperCar:
def __init__(self, __name):
self.name = __name
def __getattr__(self, item):
return 'Nothing found, sorry :(\n'
def __getattribute__(self, item):
print(f'Looking for {item}')
return object.__getattribute__(self, item)
class MyClass:
def __init__(self, __value):
self.value = __value
def __call__(self, *args, **kwargs):
print(kwargs['hello'])
class TimeManager:
def __init__(self):
pass
def __enter__(self):
self.start = datetime.now()
def __exit__(self, *args):
time.sleep(2.5)
self.end = datetime.now() - self.start
print(self.end)
def test_MyClass_SuperCar():
Tesla = SuperCar('Model Y')
# print(Tesla.name)
# print(Tesla.fuck)
a = MyClass('hello')
a(**{'hello': 'hi'})
class Value:
def __init__(self):
self.value = None
@staticmethod
def pow_mod_2(value):
return pow(value, 1, 2)
def __get__(self, instance, owner):
return self.value
def __set__(self, instance, value):
self.value = self.pow_mod_2(value)
class TestClassDescriptor:
attr = Value()
if __name__ == '__main__':
# test_MyClass_SuperCar()
# with TimeManager():
# print('Hello, I am here!')
instance = TestClassDescriptor()
instance.attr = 9
print(instance.attr)