From: Kirill S. <xi...@ga...> - 2009-02-23 17:03:10
|
> I am trying to save the python object using PyYaml but when i > implement the __getattr__() funnction, pyYaml throws an error message > "None type Oject is not callable" > > my testing script > > > import yaml > > class Page(yaml.YAMLObject): > yaml_tag = u'!Page' > def __init__(self, pageName): > self.pageName = pageName > self.annotations = {} > > def __repr__(self): > return "%s(pageName=%r,annotations=%r)" % > (self.__class__.__name__,self.pageName, self.annotations) > > > def __getattr__(self, name): > if name in self.annotations: > return self.annotations[name] > try: > filename = r'D:\d2.yaml' > fileObj = file(filename ,'w') > yaml.dump(Page('test'), fileObj) > finally: > fileObj.close() > > try: > filename = r'D:\d2.yaml' > stream = file(filename ,'r') > print yaml.load(stream) > finally: > stream.close() > > any one can suggest me how to solve this problem The bug is in the __getattr__(self, name) method. You need to add raise AttributeError(name) to the end of the method. Alternatively you may define custom __getstate__/__setstate__ methods. Thanks, Kirill |