import traceback
try:
#code here
except Exception as exception:
print(type(exception).__name__)
print(exception.__class__.__name__)
print(exception.__class__.__qualname__)
print(traceback.format_exc())
Reference : stackOverflow
from multiprocessing import Pool
def multi_process(my_func, my_args, num_processes=10):
"""my_args is a table of arguments for my_func"""
results = []
with Pool(processes=num_processes) as pool:
for result in pool.imap(my_func, my_args):
results.append(result)
return results
import pathlib
pathlib.Path(__file__).parent.resolve()
try:
#code here
except KeyboardInterrupt:
pass
#or do something
python3 -m pip install pylint
pylint <filename>
python -c "import this"
python -c "import numpy as _;print(_.__path__)"
python -c "import numpy as _;print(_.__file__)"
python -m http.server
Location:
$HOME/pip/pip.ini
$HOME/.pip/pip.conf
# show the location
pip config debug
# location location and config
pip config -v list
Can be useful for loading log data that is not properly formatted JSON. Note that this can be unsecure (RTFM).
import ast
weird_json = """{'a': 1, 'b': "2"}"""
obj = ast.literal_eval(weird_json)
print(type(obj["a"]), "=", obj["a"]) # <class 'int'> = 1
print(type(obj["b"]), "=", obj["b"]) # <class 'str'> = 2