Python

Local Docs

pydoc3 -b

Download https://docs.python.org/3/download.html and run webserver in the folder.

Oneliners

python -m http.server

IPython

# Autoreload imports
%load_ext autoreload
%autoreload 2

# Debugger
%pdb on
%pdb off

Debugger/PDB

python -m pdb myscript.py
import pdb; pdb.set_trace()
b myscript.py:10
b function
b requests/sessions.py:555
%debug function()
%pdb on
%pdb off

Argparse

def parse_args(args=sys.kwargs[1:]):
	parser = argparse.ArgumentParser()
	parsed_args = parser.parse_args(args)
	return args

Try Except

try:
    # Use "raise" to raise an error
    raise IndexError("This is an index error")
except IndexError as e:
    pass    # Pass is just a no-op. Usually you would do recovery here.
except (TypeError, NameError):
	pass    # Multiple exceptions can be handled together, if required.
else:   # Optional clause to the try/except block. Must follow all except blocks
	print "All good!"   # Runs only if the code in try raises no exceptions
finally: #  Execute under all circumstances
	print "We can clean up resources here"

Logging

import logging

logger = logging.getLogger(__name__)
# in main():
logging.basicConfig(level=logging.DEBUG)