Python Zero to Heros

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

property-based testing


Any Questions?

What is Linting

lint, or a linter, is a tool that analyzes source code to flag programming errors, bugs, stylistic errors, and suspicious constructs.[1] The term originates from a Unix utility that examined C language source code.[2]

- wikipedia


Why Linting

  1. to avoid errors (fix typos before running tests)
  2. to keep a consistance code format (increase readability)
  3. to automatically achieve no.1 and 2 (save time)
  4. Save time in code reviews


Liters/ auto-formatter

in Python

  • Flake 8
  • Autoflake
  • Black
  • Isort

To used with them: tox, pre-commit


Flake8 is a wrapper around these tools:

Ned Batchelder's McCabe script


To install

python -m pip install flask8


Invoking Flake8

flake8 --select E123

Configuring Flake8

Flake8 supports storing its configuration in the following places:

  • Your top-level user directory
  • In your project in one of setup.cfg, tox.ini, or .flake8.
ignore = D203
exclude = .git,__pycache__,docs/source/,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.


To install

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.


To install







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
black {source_file_or_directory}


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.


To install

python -m pip install isort







Skip ordering

import module  # isort:skip


Like Travis but for testing in various Python enviroments


To install



To setup: tox.ini





To run

python -m pip install tox
envlist = py36

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.


To install



python -m pip install pre-commit


To setup: .pre-commit-config.yaml

-   repo:
    rev: stable
    - id: black
      language_version: python3.6
-   repo:
    rev: 3.7.9
    - id: flake8

Install the git hook scripts

pre-commit install

Next week:

Sunday 2pm (UK time/ BST)

There are also Mid Meet Py every Wednesday 1pm

Testing month in June