From 4d1fb0ef7afcce15550cfb9c6c6f07a333e45b06 Mon Sep 17 00:00:00 2001 From: nkhamm-spb <nkhamm.spb@gmail.com> Date: Fri, 13 Jan 2023 10:26:30 +0700 Subject: [PATCH] / --- task1.py | 19 +++++++++++++++++++ task2.py | 17 +++++++++++++++++ task3.py | 0 3 files changed, 36 insertions(+) create mode 100644 task1.py create mode 100644 task2.py create mode 100644 task3.py diff --git a/task1.py b/task1.py new file mode 100644 index 0000000..218b9e6 --- /dev/null +++ b/task1.py @@ -0,0 +1,19 @@ +def my(self, attr): + try: + return object.__getattr__(self, attr) + except AttributeError: + return 0 + + +def implicit_int(cls): + cls.__getattr__ = my + return cls + + +@implicit_int +class A: + pass + + +a = A() +print(a.e) diff --git a/task2.py b/task2.py new file mode 100644 index 0000000..e513ebe --- /dev/null +++ b/task2.py @@ -0,0 +1,17 @@ +import time + + +class Timer: + time = __import__("time") + def __enter__(self): + self.st = time.time() + def __exit__(self, exc_type, exc_val, exc_tb): + if exc_type is None: + print(time.time() - self.st) + return False +import random +with Timer(): + a = 0 + for i in range(1000000): + a += random.randint(0, 1000) + print(a) \ No newline at end of file diff --git a/task3.py b/task3.py new file mode 100644 index 0000000..e69de29