Created
January 22, 2021 17:52
-
-
Save pydanny/3069e496796842e874d6bac73b5b774e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 | |
# Stolen 100% from David Winterbottom's file that I can't find right now. | |
# 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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment