Skip to content

Instantly share code, notes, and snippets.

@andrijac
Last active February 15, 2019 09:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andrijac/b533aac68244a8761bb3c626aee3177c to your computer and use it in GitHub Desktop.
Save andrijac/b533aac68244a8761bb3c626aee3177c to your computer and use it in GitHub Desktop.
#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]}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment