Random Tips -- Python

Conditional Context Manager


Type hint for an object that is not defined yet

PEP0484 - Forward references Basically you can just use string for the type hint.


Specify specific commit hash

pip install -e git+https://git.repo/some_repo.git@commit-hash

pip install from a sub-directory

Look at this stackoverflow page.

pip install -e git+https://git.repo/some_repo.git#egg=version_subpkg&subdirectory=repo

Publish a package using Github Actions CI/CD workflows


random.randint vs np.random.randint

  • np.random.randint(0, 10): 0 to 10
  • random.randint(0, 10): 0 to 9 Why...