Paul schrieb:
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
Paul
http://bidegg.com
AFAIK Yaml already supports persisting python objects:
>>> from yaml import dump
>>> class Foo(object):
... def __init__(self, name):
... self.name = name
...
>>> f = Foo('bar')
>>> dump(f)
'!!python/object:__main__.Foo {name: bar}\n'
>>>
And if you want to write your own persistence, I'd do that as yaml and
pickle do as a generic function that supports the pickle protocol.
http://docs.python.org/library/pickle.html#the-pickle-protocol
Diez
--
http://mail.python.org/mailman/listinfo/python-list