title: Python, yaml nested objects
body: <p>I am trying to create a yaml format that allow me to create an object inside another object.
  In this sample i am trying to create a State Machine object and at the same time populate it with some states and connections between them.</p>
  
  <pre><code>yaml.load("""
  !statemachine {
       states: [
         !state { name: p1 },
         !state { name: p2 },
         !state { name: p3 },],
       connections:
        [!connection { 'pim' : [p1,p2]}]}
  """)
  </code></pre>
  
  <p>!statemachine have a constructor that generates an object of type MyStateMachine</p>
  
  <p>!state have a constructor that generates an object of type MyState</p>
  
  <p>!connection have a constructor that should use object generated with name p1 and add a connection to it</p>
  
  <p>I have 2 problems here:</p>
  
  <p>1 - The constructor for <em>state</em> is called after the <em>statemachine</em> is created and the states are not present inside it</p>
  
  <p>2 - Retrieve the object p1 and invoke the method add_connection over it.</p>
  
  <p>Thanks in advance</p>