import logging
formatter = logging.Formatter('%(asctime)s %(levelname)s %(message)s')
def setup_logger(name, log_file, level=logging.INFO):
"""To setup as many loggers as you want"""
handler = logging.FileHandler(log_file)
handler.setFormatter(formatter)
logger = logging.getLogger(name)
logger.setLevel(level)
logger.addHandler(handler)
return logger
# first file logger
logger = setup_logger('first_logger', 'first_logfile.log')
logger.info('This is just info message')
# second file logger
super_logger = setup_logger('second_logger', 'second_logfile.log')
super_logger.error('This is an error message')
def another_method():
# using logger defined above also works here
logger.info('Inside method')
- Use
imageio
to read image easier
import matplotlib.pylab as plt
from imageio import imread
filename = <IMAGE_PATH>
img = imread(filename)
plt.imshow(img)
pipenv lock --pre --clear
- Make isort compatible with Black
isort --profile=black .
-
Use
vars
to access class's variable -
Some useful commands to debug
pipenv
pipenv lock --pre --clear
Your Pipfile requires python_version 3.9, but you are using 3.8.3
which python
pipenv install --python=/path/to/your/python
- Serve static website locally
python -m http.server 8000
- Download files on Google Colab
from google.colab import files
files.download("model.h5")
-
It's possible to install third party extensions directly from Jupyter Lab now
-
Jupyterlab Code Formatter Error Unable to find server plugin version (Ref: jupyterlab-contrib/jupyterlab_code_formatter#193)
jupyter server extension enable --py jupyterlab_code_formatter
- Change Kernel name (Ref: https://queirozf.com/entries/jupyter-kernels-how-to-add-change-remove)
- Use
$ jupyter kernelspec list
to see the folder the kernel is located in - In that folder, open up file
kernel.json
and edit option "display_name"