Handy utilities = Friday Filosofical Finking
DL Neil writes:
> How do you keep, use, and maintain those handy snippets, functions,
> classes... - units of code, which you employ over-and-over again?
I have two methods:
First, in my scripts directory I have a file called
"python-cheatsheet.py" where I save small tips that I
think I might not remember; mostly 2- to 5-liners.
Second, I wrote a script called langgrep that searches in known
places for files written in a specified language (it looks at file
extensions and shebangs), then greps for a pattern in all those
files. It looks in ~/bin plus a set of other directories, like
certain projects under ~/src.
So for instance if I'm trying to remember the syntax to read a CSV
file as a dictionary, I might run
langgrep python csv.DictReader
langgrep python -i csv | grep -i dict
Since you asked about importing libraries: in my ~/bin I have a
directory pythonlibs, which is in my PYTHONPATH, where I put
(usually symlinks to) python files and packages I use regularly
that aren't installed systemwide.