Skip to content

Instantly share code, notes, and snippets.

@pkulev
Last active Aug 29, 2015
Embed
What would you like to do?
from datetime import datetime
DEBUG = True
TIMER = True
def logger(func):
import sys
def inner(*args, **kwargs):
sys.stdout.write("[{}] Calling FNAME with args: {} | kwargs: {}\n".format(datetime.now(),
args,
kwargs))
res = func(*args, **kwargs)
sys.stdout.write("[{}] Result info: type::{}, value::{}\n".format(datetime.now(),
type(res),
res))
return res
return inner if DEBUG else func
def timer(func):
from datetime import datetime
def inner(*args, **kwargs):
t1 = datetime.now()
res = func(*args, **kwargs)
t2 = datetime.now()
c = t2 - t1
import sys
sys.stdout.write("[{}] Execution time: {}S : {}m\n".format(datetime.now(),
c.seconds,
c.microseconds))
return res
return inner if TIMER else func
@timer
def dummy_func(n: int, reverse: bool = True) -> int:
a = 0
for _ in range(n):
a += 1
return int(str(a)[::-1]) if reverse else a
@logger
def foo(bar, baz=0, beer=True):
return "{} {} под окном {}\n".format(baz, bar, "хуй" if beer else "Лёша")
dummy_func(100000000)
print(foo("мох", baz=0.5))
@logger
@timer
def fact(n):
if n <= 1:
return n
else:
return n * fact(n-1)
fact(150)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment