title: python: serialize a dictionary into a simple html output
body: <p>using app engine - yes i know all about django templates and other template engines.</p>
  
  <p>Lets say i have a dictionary or a simple object, i dont know its structure and i want to serialize it into html.</p>
  
  <p>so if i had</p>
  
  <pre><code>{'data':{'id':1,'title':'home','address':{'street':'some road','city':'anycity','postal':'somepostal'}}}
  </code></pre>
  
  <p>want i want is that rendered in some form of readable html using lists or tables;</p>
  
  <pre><code>data:
     id:1
     title:home
     address:
             street: some road
             city: anycity
             postal:somepostal
  </code></pre>
  
  <p>now i know i can do</p>
  
  <pre><code>for key in dict.items
  print dict[key]
  </code></pre>
  
  <p>but that wont dive into the child values and list each key, value pair when the key/value is a dictionary - ie the address dict.</p>
  
  <p>Is their a module for python that is lightweight/fast that will do this nicely. or does anyone have any simple code they can paste that might do this.</p>
  
  <p><strong>Solution</strong>
  All the solutions here were useful. pprint is no doubt the more stable means of printing the dictionary, though it falls short of returning anything near html. Though still printable. </p>
  
  <p>I ended up with this for now:</p>
  
  <pre><code>def printitems(dictObj, indent=0):
      p=[]
      p.append('&lt;ul&gt;\n')
      for k,v in dictObj.iteritems():
          if isinstance(v, dict):
              p.append('&lt;li&gt;'+ k+ ':')
              p.append(printitems(v))
              p.append('&lt;/li&gt;')
          else:
              p.append('&lt;li&gt;'+ k+ ':'+ v+ '&lt;/li&gt;')
      p.append('&lt;/ul&gt;\n')
      return '\n'.join(p)
  </code></pre>
  
  <p>It converts the dict into unordered lists which is ok for now. some css and perhaps a little tweaking should make it readable.</p>
  
  <p>Im going to reward the answer to the person that wrote the above code, i made a couple of small changes as the unordered lists were not nesting. I hope all agree that many of the solutions offered proved useful, But the above code renders a true html representation of a dictionary, even if crude.</p>