Skip to main content
  1. Notes/

Python

  • ruff
    • replaces flake8, black, isort, …
pip install --editable .

If you install your local project with -e option (pip install -e mypackage) and use it in your environment (e.g. within your other project like from mypackage import custom_function) then, when you make any change to your custom_function, you will able to use this updated version without re-installing it again (with pip install or python setup.py), which would happen in case of omitting -e flag. – Nerxis

Virtual environments #

# Create a virtual environment
python -m venv .venv

# Activate the virtual environment
source .venv/bin/activate

f-string #

integer = 42
f'{integer=}' # integer=42
f'{1 + 1 = }' # 1 + 1 = 2

fp_number = 3.1415
f'{fp_number:.2f}' # 3.14

percentage = 0.42
f'{percentage:.1%}' # 42.0%

big_number = 1_000_000
f'{big_number:_}' # 1_000_000
f'{big_number:,}' # 1,000,000
from datetime import datetime

now = datetime.now()
f'{now:%x}' # 08/09/22
f'{now:%c}' # Tue Aug  9 16:08:01 2022
f'{now:%H:%M:%S}' # 16:08:01

text = 'Hello World'
f'{text:_>20}' # _________Hello World
f'{text:*^20}' # ****Hello World*****
f'{text:<20}' # Hello World         

Source: Every F-String Trick In Python Explained – YouTube