Python Resources
Glossary
- Python Libraries: Reusable modules/packages for specific tasks (e.g., pandas, numpy).
- Python Package Development: The process of creating reusable modules and packages in Python, including structure, distribution, and maintenance.
- Package Index: Websites like PyPI for distributing and managing Python libraries.
- Continuous Integration: Tools and practices to automatically test and integrate code changes to ensure stability in shared repositories.
- Docstrings: Special comments in Python that document code functionality, making it easier for others to understand and use.
- Virtual Environments: Isolated Python installations for managing dependencies specific to a project.
- Code Linting: Tools like flake8 used to identify errors or enforce coding standards.
- Unit Testing: Writing test cases for code to ensure reliability and correctness during development.
- Code Versioning: Managing Python scripts and projects using Git to track changes and facilitate collaboration.
- Jupyter Notebook: An interactive computing environment that allows users to combine live code, equations, visualizations, and text.
Unit tests
Unit tests for SearchSources can be added to the tests/3_packages_search directory. Tests for API searches should be added to the api_search_test.py
and those for DB searches to the db_search_load_prep_test.py
(together with the required data).
To run tests, use the following command in the top-level colrev directory:
# Run all tests
pytest tests
# Run tests with verbose output
pytest tests -v
pytest tests -vv
# Run a selected test
pytest tests/3_packages_search/api_search_test.py
# Run a selected test function
pytest tests/3_packages_search/api_search_test.py -k test_eric
Virtual environments
When running code locally, it is good practice to use virtual environments (venv).
# sudo apt-get install python3-venv
python -m venv venv
source venv/bin/activate
# python -m pip install --upgrade pip
# python -m pip install -e .
deactivate
Learning resources
Introductory:
- Python challenges
- Python CheatSheet
- 11 tips for Python beginners
- PEP 8 — the Style Guide for Python Code
More advanced:
- The Hitchhiker’s Guide to Python
- RealPython Tutorials
- Python Programming for Data Science
- Python design patterns
Focused on Python packages:
Tip: You can use this tutorial for more insights in Python