Resources

Entry-point

Interactive console

$ python FLAGS

Script

$ python FLAGS SCRIPT_PATH

Module

$ python FLAGS -m MODULE

e.g.

Use a built-in module.

$ echo '[1, 2, 3'] | python3 -m json.tool
[
    1,
    2,
    3
]
$ python3 -m http.server
Serving HTTP on :: port 8000 (http://[::]:8000/) ...

Or a globally installed module.

$ pip3 install black --upgrade
$ python3 -m black --version
__main__.py, 21.12b0 (compiled: no)
$ python3 -m venv my-venv
$ python3 -m pip install PACKAGE

Flags

Use these flags either when starting the interactive console or when running a module or script. Interactive console:

Verbose

$ python -v

Unbuffered

Run in unbuffered mode, so that output is printed immediately rather than when the buffer reaches a certain size.

There are multiple ways to achieve this.

StackOverflow discussion.

$ python -u

Or if you are not using /usr/bin/env python you can add the flag to your script.

#!/usr/bin/python -u

Set PYTHONUNBUFFERED in the shell or within your script with os.env.

Or within a script on print.

print('Hello, World!', flush=True)

Or with a partial:

import functools


print = functools.partial(print, flush=True)

print('Hello, World!')