A short description of your package
Project description
Py-Decorate-All
Apply a decorator to all functions in a module.
Example Usage
from decorate_all import decorate_all_functions
decorate_all_functions(my_decorator, my_module)
decorator (function): the decorator to apply to functions module_name (string): the name of the module to apply the decorator to
If you want to apply the decorator to functions in the current module, pass __name__
the module as make sure to call decorate_all_functions
after defining the functions to decorate, i.e. at the end of the script to apply to all functions.
Here is an example for applying a decorator to all functions in a script: (works in a module or interactive console (REPL))
from decorate_all import decorate_all_functions
def test_function():
print("Hello there")
def demo_decorator(func):
def wrapper(*args, **kwargs):
result = func(*args, **kwargs)
return "Decorator was here!"
return wrapper
decorate_all_functions(demo_decorator, __name__)
print(test_function())
The output of the above code is:
Hello there
Decorator was here!
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
decorate_all-0.1.0.tar.gz
(1.6 kB
view hashes)
Built Distribution
Close
Hashes for decorate_all-0.1.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 95031543a072351323907b05d52eac4a428ffd1134b9d8d7fe927ad6e18372d8 |
|
MD5 | d29ff41299e9b33b6783b7564934d3fa |
|
BLAKE2b-256 | 24af007b8cfd57a8d7264293e63c1a83df28a79f039dfca4d39189bfca046a85 |