Coding style https://www.python.org/dev/peps/pep-0008/
.gitignore https://github.com/Microsoft/vscode-python/blob/master/.gitignore
#Python: Select Interpreter | |
#Python: Select linter | |
# -> pylint | |
#setup virtual environment | |
python -m venv .venv | |
#install rope, extracting method | |
python -m pip install -U rope --user | |
#https://stackoverflow.com/questions/2262333/is-there-a-built-in-or-more-pythonic-way-to-try-to-parse-a-string-to-an-integer | |
print("enter:") | |
in1 = input() | |
print(in1) | |
def ignore_exception(DefaultVal=None): | |
""" Decorator for ignoring exception from a function | |
e.g. @ignore_exception(DivideByZero) | |
e.g.2. ignore_exception(DivideByZero)(Divide)(2/0) | |
""" | |
def dec(function): | |
def _dec(*args, **kwargs): | |
try: | |
return function(*args, **kwargs), True | |
except Exception: | |
return DefaultVal, False | |
return _dec | |
return dec | |
sint = ignore_exception(0)(int) | |
res = sint(in1) | |
if res[1]: | |
print("OK") | |
else: | |
print("IT'S NOT OK") | |
print(f"Value: {res[0]}") |