waving android

I am currently a software engineer at Google, where as a member of the Android platform team I build frameworks and user interfaces.

The blog here at is mostly historical; you can find more recent posts on .

An end to configuration files

June 23rd, 2005

I hate configuration files, don’t you? Wouldn’t it be simpler if the user’s preferences were just hard-coded into the script?

#!/usr/bin/python

import sys, re

PASSWORD = 'bar'

if len(sys.argv) > 1:
    PASSWORD = sys.argv[1]
    
    script = open(__file__, 'r').readlines()
    for i in xrange(len(script)):
        l = script[i]
        if re.match(r'^PASSWORD =', l):
            script[i] = 'PASSWORD = %s\n' % `PASSWORD`
            break
    
    open(__file__, 'w').write(''.join(script))

print "PASSWORD = %s" % `PASSWORD`
newer: older: