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`