Python
Topics
- Python pip -> python package manager
- Python venv -> python virtual environments
- pyproject.toml -> instead of
requirements.txtorsetup.py - MyPy (TODO) -> a type checker for python
- Python ruff -> ruff a fast python linter and code formatter
- Python Conda
Python boilerplate
Simple '__main__' usage
if __name__=='__main__':
print("hello world")With main function, runnable as program:
import sys
def main() -> int:
a=2+2
print(f"2+2={a}")
if __name__=='__main__':
sys.exit(main())Creating Python packages
ModuleNotFoundError: No module named XXXX
Context:
from myfolder.myClass import myClassError:
ModuleNotFoundError: No module named 'myFolder'
Assuming you are using something like pyproject.toml, you can fix this by doing, from the home directory:
pip install -e .
python -m scripts.my_script.py
This ensures that Python set the home in the home of the project, and so