[Tutor] Generating a python file

Alan Gauld alan.gauld at btinternet.com
Tue Dec 14 11:07:58 CET 2010

"C.T. Matsumoto" <c.t.matsumoto at gmail.com> wrote

> Is it possible to create files containing python code in the same 
> sort of way that you can generate text files.

Yes, a python file is just a text file. There is nothing special about
it other than the fact that the contents happen to be Python code.

> A simple example perhaps could be a persistent dictionary. Keys and 
> values are written to the dictionary in a file, that can be imported 
> later.

You can do that and in dfact a well known email application does
something very similar. However for most situations a proper data
storage solution is better (certainly more secure).
And for simple cases pickle and shelve(for dictionaries) should
suffice. For more complex cases a config file, XML or a relational
database would be better.

Alan G.

More information about the Tutor mailing list