yaml for persistence

Aaron Brady castironpi at gmail.com
Tue Mar 3 00:53:01 EST 2009


On Mar 2, 8:19 pm, Paul <webjog... at gmail.com> wrote:
> class User(object):
>     def __init__(self, uid):
>        self.uid = uid
>        self.__dict__.update(yaml.load(str('uid')+'.yaml'))
>
>     def save(self):
>         f=open(str(self.uid)+'.yaml')
>         yaml.dump(self.__dict__, f)
>
> is there a better way to persist using Yaml
>
> Paulhttp://bidegg.com

Just a design consideration: Perhaps you want a separate dictionary to
contain the YAML attributes.  You can delegate extra objects to it
with getattr and setattr.  Or get extra objects with getitem and
setitem.  Otherwise, you might want 'save' and 'uid' to have a leading
underscore.

By better, do you mean more concise, easier to access, more robust, or
etc.?



More information about the Python-list mailing list