expanding persistent objects

Dennis E. Hamilton infonuovo at email.com
Mon Mar 27 15:08:41 EST 2000


How wonderful!  Anticipating how to preserve access to preserve material in
the face of change.  Good for you.  I love efforts like that.  Please let me
know what you learn and what approach you end up taking.

First, I would suggest that you use an ASCII file format that is
Python-independent.  That way, you know you can recover your data in the
future using any tool that is available.

Well, here's a too-pat suggestion for how to do that.  Consider using an
XML-formatted file as a persistent storage form.  You don't actually have to
have a DTD to work from at first, as long as you have a good idea of the
structure you want to store serially. Make sure there is something in the
preamble tags for the overall collection that identifies the version of the
persistent form, so that when you re-ingest it for operational work younger
software can tell when it is seeing an older version.

I would also look at ways of having the rules be such that *older* software
could read a newer file and do the best it can (maybe refusing to update or
warning you that extracting a new update may set you back).  And see if you
can anticipate having any new attributes and elements being optional in the
future.

I hate to acknowledge this feature of Python, but the way Python objects
work without having a predetermined strongly-typed structure operates in
your favor here.  I think you can ingest XML and deliver an object with
appropriate internals and attributes without much difficulty, so long as all
literal values are strings.  (Or you have an initial object to use as a
"template" to fill up.)

This may be too fancy for what you want.  An easy way is to use a dict of
lists or list of tuples of name-value pairs or something like that.  All
recorded in Python syntax.   Then you could write it to a file in python
form.  Then all you have to do is import it to have it instantiated back in
a Python program.  That would be the simple way.  If pickling is that easy
to inspect, then that might be good enough.

The XML approach might take more learning curve but leave you with a
more-adaptable technique for future applications.

Is this close to what you where looking to find out?

-- Dennis





-----Original Message-----
From: python-list-admin at python.org
[mailto:python-list-admin at python.org]On Behalf Of Pete Shinners
Sent: Monday, March 27, 2000 10:56
To: python-list at python.org
Subject: expanding persistant objects


i'm learning python here and have a question about storing
persistant objects. i plan to keep a real simple list of
users and i want to know the best way to simple store it
and reload it.
my only concern is that later i'll probably want to add
more fields to each users record. can simple pickling
handle this? do i need to use one of the DB storage
libraries?

i'm worried if i start saving the data one way, when i go
to add extra fields i wont be able to load the files anymore.

thanks for any guidance!


--
http://www.python.org/mailman/listinfo/python-list





More information about the Python-list mailing list