Handy decorators for day-to-day use!
Project description
Handy Decorators
This is a set of handy decorators which one can use for their day-to-day life coding.
Installation Method
Install it via pip
pip install handy-decorators
Description
The set of decorators contain some daily needed decorators for being used in our day to day coding life. This has following set of decorators.
trycatch
This decorator surounds your function with a try-except block and if your code/function raises an exception, it's caught by this decorator and reported by logging.
>>> from decorators import trycatch
>>> @trycatch
... def func():
... print(0/0) # Division by 0 must raise exception
...
>>> func()
Exception occurred: [integer division or modulo by zero]
>>>
timer
This decorator will calculate a time required in seconds by your function for execution.
>>> from decorators import timer
>>> @timer
... def a():
... import time
... print('Hi')
... time.sleep(1)
...
>>> a()
Hi
Time taken by the function is [1.00103902817] sec
>>>
singleton
This decorator is for making your class singleton.
The features given by this decorator are:
- If instances of same class are created with same args and kwargs, decorator will return previously existing instance
- If instances of same class are created with different args and kwargs, decorator will create a different one for you and store the newly created instance
>>> from decorators import singleton
>>>
>>> @singleton
... class A:
... def __init__(self, *args, **kwargs):
... pass
...
>>>
>>> a = A(name='Siddhesh')
>>> b = A(name='Siddhesh', lname='Sathe')
>>> c = A(name='Siddhesh', lname='Sathe')
>>> a is b # has to be different
False
>>> b is c # has to be same
True
>>>
Please create an issue if more decorators are needed.
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 Distributions
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file handy_decorators-0.0.7-py2-none-any.whl.
File metadata
- Download URL: handy_decorators-0.0.7-py2-none-any.whl
- Upload date:
- Size: 15.4 kB
- Tags: Python 2
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/2.7.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
953deea0a2836d2944436b2b2e6d9e4d980d9b37fc1a75b0fc95cbc8a018aa27
|
|
| MD5 |
759263d00ad2bf12803cf00f732f6b27
|
|
| BLAKE2b-256 |
bcf899c760e4f1c6226add1b358a740fe1b1d5bb5fe488dd601acb1446a3bda2
|