Re: PyYAML - Help with redefining to_yaml and multiple documents

Sean <[email protected]>
Newsgroups gmane.text.yaml.general
Message-ID <[email protected]>
I apologize if this is posted multiple times.  I had a little trouble with
the mailing list and google groups.  Hopefully I have it figured out now.



I have a simple python class containing 2 dicts.  I'd like to
> represent an instance of the class as two yaml documents, with the ---
> document start token separating the 2 dicts.  I think I need to
> redefine to_yaml to do this, but I'm not really sure how to get both
> documents into the stream.
>
> import yaml
> class Info(yaml.YAMLObject):
>    yaml_tag = u'Info'
>    def __init__(self):
>        self.firstDoc={1: 'one', 2: 'two', 3: 'three'}
>        self.secondDoc={4: 'four', 5: 'five'}
>
>    @classmethod
>    def to_yaml(cls,dumper,data):
>        return dumper.represent_mapping(tag=u'tag:yaml.org,
> 2002:map',mapping=data.firstDoc)
>
> if __name__ == "__main__":
>    print yaml.dump(Info(),default_flow_style=False)
>
>
> The output from the above is:
> 1: one
> 2: two
> 3: three
>
>
> I would like output like:
> ---
> 1: one
> 2: two
> 3: three
> ---
> 4: four
> 5: five
>
> Any ideas or pointers?
>
> Thanks,
> Sean

------------------------------------------------------------------------------
Download Intel&#174; Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev

_______________________________________________
Yaml-core mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/yaml-core
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.