[Tutor] How to model objects aimed to persistence?

Knacktus knacktus at googlemail.com
Wed Jun 16 22:39:44 CEST 2010


Hi everyone,

within a python application I can easily model object association with 
simple references, e.g.:

#################################################################
class FavoritMovies(object):
     def __init__(self, movies):
         self.movies = movies

class Movie(object):
     def __init__(self, name, actor):
         self.name = name
         self.actor = actor

gladiator = Movie("Gladiator", "Russel Crowe")
my_favorit_movies = FavoritMovies([gladiator])

kung_fu_panda = Movie("Kung Fu Panda", "Jack Black")
your_favorit_movies = FavoritMovies([gladiator, kung_fu_panda])
##################################################################

So far, so good. But what is best practise to prepare this data for 
general persistence? It should be usable for serialisation to xml or 
storing to an RDBMS or ObjectDatabase ...

I guess I have to incorporate some kind of id for every object and use 
this as reference with some kind of look-up dictionary, but I wouldn't 
like it and hope that there're some other sweet pythonic solutions?

Cheers,

Jan


More information about the Tutor mailing list