python-CSD-kursu/python-temel/log.dekorator.2.py
2023-08-07 18:10:37 +03:00

24 lines
393 B
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import datetime
import time
def log(path):
file = open(path, 'w')
def bar(f):
def tar(*args, **kwargs):
dt = datetime.datetime.now()
print(dt)
file.write(str(dt) + '\n')
f(*args, **kwargs)
return tar
return bar
@log('log.txt')
def foo():
print('foo çağrıldı')
foo()
time.sleep(3)
foo()
time.sleep(2)
foo()