Saving / Restoring data in a program

darrell dgallion at yahoo.com
Thu Nov 27 11:45:04 EST 2003


I like files that people can read and edit.
So I write valid python to a file to save config data.
Then import it later.

fp=open("config",'w')
print >>fp, "config={"
for k,v in myDict.items():
	print >>fp, "%s:%s,"%(`k`,`v`)
print >>fp,"}"

pprint is good for this also.
repr works but you get very long lines.

With extra effort, XML would be good for this also.

--Darrell






More information about the Python-list mailing list