A trick that I've found useful is to make a toolbox of methods that I re-use often. That way, when I need to, say, read and parse a quirky file format I can just do this
from toolbox import texttools as ttl ttl.parse_weird_file(filename)
parse_weird_file() is a function that I
meticulously copied, pasted, and tweaked from StackOverflow
a long time ago. There are a few steps at the command line
to set this up, but nothing
- Navigate to the directory you want this to live.
mkdir -p toolbox/toolbox.
echo "from setuptools import setup" > toolbox/setup.py
echo "setup(name='toolbox')" >> toolbox/setup.py
python3 -m pip install -e toolbox
toolbox/toolbox/texttools.pycontaining the function
parse_weird_file()and you are good to go!
Now any changes you make to
texttools.py or any other
files you add to
toolbox/toolbox will be available
for python3 to import, no matter which directory you're working in.
It's guaranteed to cut your googling time in half.