Skip to content

Instantly share code, notes, and snippets.

@codeinthehole
Created December 30, 2020 11:41
Show Gist options
  • Star 9 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save codeinthehole/caafd18ecf215b8113ffea167c78dc28 to your computer and use it in GitHub Desktop.
Save codeinthehole/caafd18ecf215b8113ffea167c78dc28 to your computer and use it in GitHub Desktop.
Python start-up file
# Python start-up file
# --------------------
# Ensure a PYTHONSTARTUP environment variable points to the location of this file.
# See https://docs.python.org/3/using/cmdline.html#envvar-PYTHONSTARTUP
# Always have pp available
from pprint import pprint as pp
# Pre-emptively import datetime as I use it a lot.
import datetime
# Import rich (https://rich.readthedocs.io/en/latest/introduction.html) to get prettier
# output in the REPL.
try:
from rich import pretty as __pretty, inspect as __inspect
except ImportError:
# rich won't necessarily be installed in all environments
__inspect = pp
else:
# Ensure printing is pretty by default.
__pretty.install()
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
@EmperorMykeylo
Copy link

I don't get

Maybe because I am amateur

@mickeypash
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