title: Recursively print all attributes, lists, dicts, etc of an object in Python
body: <p>Using Python 2.7.10, I have this script:</p>
  
  <pre><code>#!/usr/bin/python
  
  #Do `sudo pip install boto3` first
  import boto3
  import json
  
  def generate(key, value):
      """
      Creates a nicely formatted Key(Value) item for output
      """
      return '{}={}'.format(key, value)
  
  def main():
      ec2 = boto3.resource('ec2', region_name="us-west-2")
      volumes = ec2.volumes.all()
      for vol in volumes:
          #print(vol.__str__())
          #print(vol.__dict__)
          print vol
  
       # vol object has many attributes, which can be another class object. 
       # For ex:
              #vol.volume_id),
              #vol.availability_zone),
              #vol.volume_type),
  
          # only process when there are tags to process
          # HERE: tags is another object which can contain a dict/list
          #if vol.tags:
          #    for _ in vol.tags:
          #        # Get all of the tags
          #        output_parts.extend([
          #            generate(_.get('Key'), _.get('Value')),
          #        ])
  
  
          # output everything at once.
          print ','.join(output_parts)
  
  if __name__ == '__main__':
      main()
  </code></pre>
  
  <p>Is there a single function which can recursively print all the object's attributes using a single call? How can I print the values of val.xxxxx and val.tags.xxxx in one call.</p>
  
  <p>I tried printing the object using <code>.__dict__</code> or <code>.__str__()</code> but it didn't help.</p>