How to create a Python decorator that can wrap either coroutine or function?

May be you can find better way to do it, but, for example, you can just move your wrapping logic to some context manager to prevent code duplication: import asyncio import functools import time from contextlib import contextmanager def duration(func): @contextmanager def wrapping_logic(): start_ts = time.time() yield dur = time.time() – start_ts print(‘{} took {:.2} … Read more

Understand the “Decorator Pattern” with a real world example [closed]

Decorator pattern achieves a single objective of dynamically adding responsibilities to any object. Consider a case of a pizza shop. In the pizza shop they will sell few pizza varieties and they will also provide toppings in the menu. Now imagine a situation wherein if the pizza shop has to provide prices for each combination … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)