Computer >> Hướng Dẫn Máy Tính >  >> Lập Trình >> Python

Python Coding Standards / Best Practices

1. PEP8 - Holy grail của Python style. Dùng linter extension cho editor. PEP8 Guide

2. Project Structure

README.rst LICENSE setup.py requirements.txt
sample/__init__.py sample/core.py sample/helpers.py
docs/conf.py docs/index.rst
tests/test_basic.py tests/test_advanced.py

3. Doctests - Test embedded trong docstring, cho phép TDD.

4. PyPi + pip - Dùng package manager thay vì tự build.

5. Pythonic Code - Tuân thủ idioms: list comprehension, context manager, duck typing... Idiomatic Python