Wednesday, April 23, 2008

Play with Configuration files using Python

Today, the main purpose of most of the administrator GUI utilities is to modify the respective configuration files. The most reliable way to modify the configuration file  is to  use  editors like vi or emacs and modify it by hand.
Python provides a better and easy way to play with our configuration files… by using the configobj module. So we can create our own administrative utilities using python (either standalone apps or cgi applications)

http://sourceforge.net/projects/configobj

The configobj module is fully utf-8 encoding compatible. So it doesn’t matter whether your configuration is in English or say for example in Hindi.

Many projects like Bazaar, Turbogears etc are using this module for reading and modifying the configuration files.To modify a config file is as easy as…

from configobj import ConfigObj
config = ConfigObj()
config.filename = filename
#
config['keyword1'] = value1
config['keyword2'] = value2
config.write()

done….. :) , it is that easy….

Refer these links for further information…

http://www.voidspace.org.uk/python/configobj.html#introduction
http://www.linuxjournal.com/article/3616

My idea is to create some customised gui (in Tkinter for portability) for my favourite tools like subversion for administration (in the future , of course)

Posted by maxinbjohn at 10:03:01 | Permalink | No Comments »