Compare commits
1 Commits
supermaste
...
supermaste
Author | SHA1 | Date |
---|---|---|
|
4d1fb0ef7a | 2 years ago |
@ -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) |
@ -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) |
Loading…
Reference in new issue