trick

Simple and quick command line argument handling in Python

17 January, 2012 - 00:08

When creating a command line tool, you quickly are faced with the burden of handling command line arguments (parsing options, arguments, flags, etc).
In Python, the optparse module or, its newer version, the argparse module are very nice solutions to build powerful command line interfaces, completely with automatically generated help.

Sometimes however, you just want a quick, simple and small way to get from A to B without a lot of overhead and overkill. Below I'll show you a quick and simple Python trick for command line handling by directly mapping the command line arguments to function arguments.

Read more...

Python: hiding attribute getters and setters behind standard attribute access

22 September, 2009 - 15:41
Categories:

Look at this small snippet of Python code:

x = TooMuchAlcohol()
 
x.value = 10
print x.value
 
x.value = 'foo'
print x.value
 
x.value = [1,2,3]
print x.value

Seems like pretty boring stuff, but look what it spits out:

20
foofoo
[1, 2, 3, 1, 2, 3]

Oh my god, I see everythin' double!

Read more...

LaTeX: inline BibTeX entries with the bibentry package

17 July, 2009 - 11:28

In the introduction chapter of my PhD dissertation, I had to make a listing of my publications. The obvious brain dead way to achieve this is just typing everything manually in a list. But this feels just so wrong when you're already using BibTeX for managing references and bibliographical stuff. However, the traditional usage of BibTeX in LaTeX is to generate a full list of all references and put this in a dedicated section or chapter.

With the bibentry package (which is part of the natlib package actually) it is possible to put bibliographic entries anywhere in the text. As far as I know and experienced, the bibentry package is included in a default LaTeX setup, so you don't have to install something, just enable it in your document.

Getting it work as desired can take some trial and error, so I thought it may be a good idea to feed "them search engines" with a working example.

Read more...

LaTeX trick: putting the subversion revision number on every page

8 February, 2008 - 18:40
Categories:

I mostly use LaTeX for writing documents (LyX actually, but that doesn't matter here) and use Subversion for the version control. For managing the revision info of a source code file I use Subversion's built in feature Keyword Substitution which expands some special keyword (like $Date$ or $Revision$) in the source code to their current values.

Now two questions arise here:

  1. How to get the Subversion keywords nicely into LaTeX? Note that the $ character used for the Subversion keywords is already a reserved LaTeX control character and make things messy.
  2. How to get the version info on every page (e.g. as a footer)?
Read more...

LaTeX trick: customizing captions

29 January, 2008 - 16:34
Categories:

Captions of floats (figures and tables) in LaTeX are by default typeset the same way as the body text. For better readability it could be appropriate to use a different font, font size or margin for the captions. This is possible with the LaTeX package caption.

Read more...