Re: problem in dumping the Object by pyYAML

Kirill Simonov <[email protected]>
Newsgroups gmane.text.yaml.general
Message-ID <[email protected]>
>      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

------------------------------------------------------------------------------
Open Source Business Conference (OSBC), March 24-25, 2009, San Francisco, CA
-OSBC tackles the biggest issue in open source: Open Sourcing the Enterprise
-Strategies to boost innovation and cut costs with open source participation
-Receive a $600 discount off the registration fee with the source code: SFAD
http://p.sf.net/sfu/XcvMzF8H
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.