Skip to content

Instantly share code, notes, and snippets.

Created December 30, 2020 11:41
What would you like to do?
Python start-up file
# Python start-up file
# --------------------
# Ensure a PYTHONSTARTUP environment variable points to the location of this file.
# See
# Always have pp available
from pprint import pprint as pp
# Pre-emptively import datetime as I use it a lot.
import datetime
# Import rich ( to get prettier
# output in the REPL.
from rich import pretty as __pretty, inspect as __inspect
except ImportError:
# rich won't necessarily be installed in all environments
__inspect = pp
# Ensure printing is pretty by default.
def inspect(*args, **kwargs):
# Custom rich.inspect wrapper to ensure methods are inspected by default.
if "methods" not in kwargs:
kwargs["methods"] = True
__inspect(*args, **kwargs)
# Print the commands that have been imported as a memory jogger.
print(">>> from pprint import pprint as pp")
print(">>> from rich import inspect")
print(">>> import datetime")
# Define aliases for true, false and null so JSON can be pasted straight in.
true = True
false = False
null = None
Copy link

I don't get

Maybe because I am amateur

Copy link

This is pretty awesome! I was completely unaware of PYTHONSTARTUP.

What are your thoughts on iPython, bpython?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment