Django uses a number of settings typically defined in the settings module within a project. These can be loaded into the interactive python shell for extra interactive fun.
from django.core.management import setup_environ
from myapp import settings
setup_environ(settings)
django, shell
Migrated from my local machine to a remote server a data analysis that plots data using Python’s matplotlib and saves the plots to PNGs. Running the analysis turned up an unexpected error that ends by noting:
no display name and no $DISPLAY environment variable
Bummer. A quick search turned up more documentation on this from both the official matplotlib documentation on using matplotlib in a webapp and generating PNGs in matplotlib when DISPLAY is not defined.
The two typical solutions are to explicitly set a backend in the Python code (this must be done before any other matplotlib imports):
import matplotlib
# Force matplotlib to not use any Xwindows backend.
matplotlib.use('Agg')
or set the backend using the matplotlibrc file.
I’m a command line junkie who only turns to higher level scripting when
a line of piped together commands falls short. A common task that I run
into is summing a column of data from a text file. Typically, my data
is in a gnuplot friendly format makes extracting the column easy:
grep -v "^#" bandwidth.dat | cut -f3 -d' '
Now what is an easy way to sum that data? I’ve seen solutions using
awk, but I’m not much of an awk fan. Much more exciting is a version
using paste:
grep -v "^#" bandwidth.dat | cut -f3 -d' ' | paste -sd + | bc