title: Python: Printing nested classes
body: <p>What's the best way to print the contents of a nested class? For example:</p>
  
  <pre><code>class Library():
      def __init__(self):
          self.shelves = []
          self.shelf = self.Shelf()
  
      class Shelf():
          def __init__(self):
              self.books = []
  
  
  x = Library()
  </code></pre>
  
  <p>I know vars(x) works if the class is not nested. But if it is, I get something like:</p>
  
  <pre><code>{'shelf': &lt;__main__.Shelf instance at 0x7f4bae723560&gt;, 'shelves': []}
  </code></pre>
  
  <p>as the output. How do I get python to print it out as:</p>
  
  <pre><code>{'shelf': {'books': []}, 'shelves': []}
  </code></pre>