python -m

pretty print a json

python -m json.tool will format a string

$ cat data/example.json
[{"fieldname0": "User", "fieldname1": "Country", "fieldname2": "Age"}, {"fieldname0": "Alex", "fieldname1": "US", "fieldname2": "25"}, {"fieldname0": "Ben", "fieldname1": "US", "fieldname2": "24"}, {"fieldname0": "Dennis", "fieldname1": "UK", "fieldname2": "25"}, {"fieldname0": "Yuvi", "fieldname1": "IN", "fieldname2": "24"}](django-admin-cookbook)

$ cat data/example.json | python -m json.tool
        "fieldname0": "User",
        "fieldname1": "Country",
        "fieldname2": "Age"
        "fieldname0": "Alex",
        "fieldname1": "US",
        "fieldname2": "25"
        "fieldname0": "Ben",
        "fieldname1": "US",
        "fieldname2": "24"
        "fieldname0": "Dennis",
        "fieldname1": "UK",
        "fieldname2": "25"
        "fieldname0": "Yuvi",
        "fieldname1": "IN",
        "fieldname2": "24"

Expose a folder to a static file server

python -m http.server will start a server on port 8000 which will server the files from current dir.

$ python -m http.server 8844
Serving HTTP on port 8844 ( ...

A simple editor for Python

Every python install comes with the idle editor, you can start it like this python -m idlelib.idle

Debugging emails

$ python -m smtpd -n -c DebuggingServer localhost:1025

Profiling scripts

$ python -m cProfile

Creating virtual environments

$ python -m venv venv_name

Running doctests

Assuming you have with next content:

def is_palindrome(text):
    Check if input text is palindrome

    >>> is_palindrome('eye')

    >>> is_palindrome('tree')
    return text == text[::-1]

To run doctests:

$ python -m doctest

Getting info on your python environment

python -m site

This prints

sys.path = [
USER_BASE: '/Users/shabda/.local' (exists)
USER_SITE: '/Users/shabda/.local/lib/python3.6/site-packages' (exists)