Skip to content

Instantly share code, notes, and snippets.

@cdgriffith
Last active November 21, 2020 04:56
Show Gist options
  • Save cdgriffith/e0d8692fc307cc46cfcda2d8c4edd562 to your computer and use it in GitHub Desktop.
Save cdgriffith/e0d8692fc307cc46cfcda2d8c4edd562 to your computer and use it in GitHub Desktop.
Python RC file
# In .bashrc and .profile
# export PYTHONSTARTUP="$HOME/.pythonrc.py"
# pip install python-box reusables pdir2
from __future__ import print_function, with_statement, absolute_import
try:
from box import Box, BoxList
except ImportError:
print("Box not available")
try:
import reusables
from reusables.cli import *
except ImportError:
print("Reusables not available")
try:
import pdir
except ImportError:
print("pdir not available")
import os
import sys
print('Python {0} on {1}'.format(".".join(str(x) for x in sys.version_info[:3]), sys.platform))
@cdgriffith
Copy link
Author

Just like a .bashrc file, you can have a .pythonrc file that is called at startup on Python consoles.

All the mentioned files are to go in $HOME and will require any active terminals to be restarted to take effect (or manually sourceed again).

Each external library is in it's own try except, that way no matter which python environment we are running, we import as many as possible.

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