much better, now for some style changes:
1) use with open(filename, 'w') as target
2) when using a variable instead of:
target.write("host = " + db_host + "\n")

do:
target.write("host = %s\n" % db_host)

Thanks for making this work so far!