Online Absolute Beginner Python Tutorials
Every Sunday 2pm (UK time/ BST)
Get this slide deck:
Python objects - int, float, str, list, dict, bool
Control flows - if-else, for loop, while loop
Functions, modeuls, classes and decorators
strings operations and regex with re
pytest with fixtures and mock
To used with them: tox, pre-commit
Flake8 is a wrapper around these tools:
Ned Batchelder's McCabe script
python -m pip install flask8
flake8 --select E123
Flake8 supports storing its configuration in the following places:
[flake8] ignore = D203 exclude = .git,__pycache__,docs/source/conf.py,old,build,dist max-complexity = 10
autoflake removes unused imports and unused variables from Python code. It makes use of pyflakes to do this.
By default, autoflake only removes unused imports for modules that are part of the standard library. (Other modules may have side effects that make them unsafe to remove automatically.) Removal of unused variables is also disabled by default.
python -m pip install autoflake
Excluding specific lines
add a # noqa comment at the end of the line
from .endpoints import user, utils # noqa
The Uncompromising Code Formatter
Black is the uncompromising Python code formatter. By using it, you agree to cede control over minutiae of hand-formatting. In return, Black gives you speed, determinism, and freedom from pycodestyle nagging about formatting. You will save time and mental energy for more important matters.
Blackened code looks the same regardless of the project you're reading. Formatting becomes transparent after a while and you can focus on the content instead.
Black makes code review faster by producing the smallest diffs possible.
Black reformats entire files in place. It is not configurable. It doesn't take previous formatting into account. It doesn't reformat blocks that start with # fmt: off and end with # fmt: on. # fmt: on/off have to be on the same level of indentation.
python -m pip install black
isort is a Python utility / library to sort imports alphabetically, and automatically separated into sections. It provides a command line utility, Python library and plugins for various editors to quickly sort all your imports.
python -m pip install isort
isort mypythonfile.py mypythonfile2.py
import module # isort:skip
Like Travis but for testing in various Python enviroments
To setup: tox.ini
python -m pip install tox
[tox] envlist = py36 [testenv] deps = pytest commands = pytest
Run commit hooks on every commit to automatically point out issues in code such as missing semicolons, trailing whitespace, and debug statements.
python -m pip install pre-commit
To setup: .pre-commit-config.yaml
repos: - repo: https://github.com/ambv/black rev: stable hooks: - id: black language_version: python3.6 - repo: https://gitlab.com/pycqa/flake8 rev: 3.7.9 hooks: - id: flake8
Install the git hook scripts
Sunday 2pm (UK time/ BST)
There are also Mid Meet Py every Wednesday 1pm
Testing month in June