Archives: January 2010

Strategy pattern in python

Here is an example of strategy pattern in python. The alogrithm that varies in this example is the conversion of csv file to xml, html and any other formats. The client is the CsvUtil class. As you can see we can change the conversion at run time and also we can apply all the alogrithm

Read on »

Split tag and namespace in lxml

I was using the target parser method of lxml as suggested here and could not turn off fully qualified name for tags and so wrote quick one to split namespace from tag name… [sourcecode language=”python”] def _gettagns(self,tag): """ returns a tuple of namespace,name """ if tag[:1] == "{": return tag[1:].split("}", 1) else: return (None,tag) [/sourcecode]

Read on »

Template method design pattern in python.

Here is an example of implementing template method in python. This example assumes that ONLY meat in the burrito varies and so the child class implements the template method of selecting the meat while rest of the work is done by the base class… Gist: https://gist.github.com/rajaramanathan/0a6b9e4bc98d022cf2da

Read on »

Reverse dns on mac.

Having used windows for a long time which uses nslookup command tool to do the reverse dns, i was trying to find a similar tool in mac. I always tend to forget that Mr.Mac is built on Unix. So you can use the host command just as in any other unix to do reverse dns

Read on »