title: Get Attribute Name in For Loop
body: <p>How do I get the attribute names and values of an object? I'm attempting to cast it to a dictionary so that I can easily JSON serialize the object.</p>
  
  <p>Code:</p>
  
  <pre><code>class User:
      ...
      def to_dict( self ):
          dict = {}
          for key, value in filter( lambda aname: not aname.startswith('_'), dir(self) ):
              dict[key] = value
      return dict
  </code></pre>
  
  <p>Error:</p>
  
  <pre><code>too many values to unpack
  </code></pre>
  
  <p>Use:</p>
  
  <pre><code>user = User({
      's_email': 'bob@email.com',
      's_password': 'password',
  })
  user.to_dict()
  # JSON Serialize
  </code></pre>