developerWorks: Python Persistence Management
Nov 18, 2002, 07:00 (0 Talkback[s])
(Other stories by Patrick K. O'Brien)
"The basic idea of persistence is fairly simple. Let's say
you've got a Python program, perhaps to manage your daily to-do
list, and you want to save your application objects (your to-do
items) between uses of the program. In other words, you want to
store your objects to disk and retrieve them later. That's
persistence. To accomplish that goal you've got several options,
each with advantages and disadvantages.
"For example, you could store your object's data in some kind of
formatted text file, such as a CSV file. Or you could use a
relational database, such as Gadfly, MySQL, PostgreSQL, or DB2.
These file formats and databases are well established, and Python
has robust interfaces for all of these storage mechanisms.
"One thing these storage mechanisms all have in common is that
data is stored independent of the objects and programs that operate
on the data. The benefit is that the data then becomes available as
a shared resource for other applications. The drawback is that
allowing access to an object's data in this way violates the
object-oriented principle of encapsulation, in which an object's
data should only be accessible through its own, public