Re: pyYAML constructor

Kirill Simonov <[email protected]>
Newsgroups gmane.text.yaml.general
Message-ID <[email protected]>
Hi Fabrizio,

> Hello all,
> I am trying to use the PyYAML capability to construct instances of python 
> objects, but when I run the following program, it seems to me that no instance 
> of the class Test appears. What I am missing?

An assignment.  Try this:

==========
import yaml

class Test(yaml.YAMLObject):
    yaml_tag = u'!Test'

    def __init__(self, name):
        self.name = name

    def __repr__(self):
        return "%s(name=%r)" % (self.__class__.__name__, self.name)


test = yaml.load("""
--- !Test
name: my name is Test
""")

print test
==========

Thanks,
Kirill

-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
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.