Named functions, ignore Exceptions decorator with parameters, multiple functions execution ...
Project description
Some useful stuff for functions
NamedFunction
pip install useful-functions-easier-life
namedfunctiontest = NamedFunction(
name="myfunction",
execute_function=execute_several_functions_insideout(
lambda x: x * 100, lambda x: x / 10, lambda x: x * 5, lambda x: x + 1000
),
name_function=lambda: "This is my function",
str_prefix="Surprise",
print_before_execution="My function\n",
str_suffix="Let's go!",
ljust_prefix=10,
rjust_prefix=30,
ljust_suffix=20,
rjust_suffix=10,
)
namedfunctiontest
Out[3]: Surprise This is my function Let's go!
#Without namedfunction:
#ca2
#Out[7]: <function __main__.execute_several_functions_insideout.<locals>.deco(f)>
namedfunctiontest(5)
My function
Out[6]: 50250.0
ignore_exceptions_decorator
from random import choice
@ignore_exceptions_decorator(print_exception=True, exception_value=False, disable=False)
def testest(number):
if number == 0:
return True
elif number == 1:
print(number / 0)
return True
testex = [testest(choice([0, 1])) for x in range(10)]
division by zero
division by zero
testex
Out[3]: [True, True, False, True, False, True, True, True, True, True]
#https://stackoverflow.com/questions/5929107/decorators-with-parameters
#Blueprint for other useful stuff
execute_several_functions_insideout
ca2 = execute_several_functions_insideout(
lambda x: x * 100, lambda x: x / 10, lambda x: x * 5, lambda x: x + 1000
)
ca2(5)
Out[6]: 50250.0
(1000+5) * 5 / 10 * 100
Out[18]: 50250.0
execute_several_functions_one_after_another
allfunctions=lambda x: (x, isinstance(x,str)),lambda x: str(x) + '-1000', lambda x:x*5, lambda x: isinstance(x,str)
ca=execute_several_functions_one_after_another(allfunctions)
ca(101)
Out[4]: [(101, False), '101-1000', 505, False]
ignore_exceptions
testex = [ignore_exceptions(divmod, 50, choice([0, 1])) for x in range(10)]
Out[11]:
[(50, 0),
(50, 0),
(50, 0),
None,
(50, 0),
(50, 0),
None,
None,
(50, 0),
(50, 0)]
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Close
Hashes for useful_functions_easier_life-0.11.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0bcbfdd670754730adea28face96b7c9c53f2d5d075be9299c6fcb57cda46f80 |
|
MD5 | 57f24bde7ca21ed26d8d065e329c49bc |
|
BLAKE2b-256 | 0a826eb6eca0f9b420ab55f8dc2092681c18b5161d47fd558ccb80535fba40b3 |
Close
Hashes for useful_functions_easier_life-0.11-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 720f7138679ff2bc9457a28254696afcb5b605dd0bd2e6599339129c0663b9d0 |
|
MD5 | 4e40087f6a10f879511f46b35fc5662c |
|
BLAKE2b-256 | c9c09e3f57f3370b448b909904072c39c3d8cb48d953d3a4bcef5d762d6fd150 |