Created
December 30, 2020 11:41
-
-
Save codeinthehole/caafd18ecf215b8113ffea167c78dc28 to your computer and use it in GitHub Desktop.
Python start-up file
This file contains 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 | |
# 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 |
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
I don't get
Maybe because I am amateur