For some small tools or jobs I use Jython so I can (re)use some existing Java code, while still writing in Python. I also have various custom Python modules, of which I put the paths in my
PYTHONPATH environment variable, so those modules are easily available in Python scripts …
Today I struggled a bit with pylab's plot_date function and overlapping date tick labels:
After some googling, I found that matplotlib offers nice flexible date tick control and formatting. I added a date tick locator and a date formatter to the mix as follows:
import pylab import matplotlib import matplotlib …
It's possible to make Subversion ignore unversioned files, so they don't show up in the status overview and you get a better signal to noise ratio. The command line interface to add ignore rules this is however a bit clunky. First, you need to remember following command:
svn propedit svn …
Parsing a subversion Id keyword is just a matter of some regular expression magic:
# use the built in regular expression library import re # the subversion Id keyword svnid = '$Id: svnidparse.py 1234 2008-02-19 09:59:27Z joske $' # bow for the mighty regular expression svnidrep = r'^\$Id: (?P<filename>.+) (?P<revision …
Howto install and use
lp_solveand its Python extension module as non root on Linux?
Compile and install the
lp_solve_126.96.36.199_source.tar.gzfrom SourceForge and untar so you get a directory
With the python module
inspect, one can inspect (not kidding) the run-time python stack. Among other things, this makes it possible to get the name of the current function or callers. Handy for logging or debugging purposes. A simple script to illustrate:
import inspect # functions def whoami(): return inspect.stack …
Quick note to self on how to get the current working directory of in a Python script, like you have
pwd(print working directory) on a Linux/Unix command line:
import os print os.getcwd()
This weekend I encountered a weird problem during programming C extension modules for Python. For some obscure reason floats from my C extension modules were formatted with a comma as separater (e.g.
123,456) instead of with the more familiar point (e.g.
123.456). Obviously some locale related …
Scipy is a (set of) open source Python modules for scientific/mathematical/engineering stuff. I (try to) use it instead of Matlab or its open source clone Octave because I don't like Matlab's scripting language and prefer Python's programming features.
If you want to store a 2D array (aka matrix …
The OpenDocument file format (aka "OASIS Open Document Format for Office Applications"), is an open and free standard for office files. It's fairly easy to read OpenDocument files in/from Python. Basicly, an OpenDocument file is just a zip archive but with another extension (".ods" spreadsheets, ".odt" for text documents …