title: Print all variables in a class? - Python
body: <p>I'm making a program that can access data stored inside a class. So for example I have this class:</p>
  
  <pre><code>#!/usr/bin/env python
  import shelve
  
  cur_dir = '.'
  
  class Person:
      def __init__(self, name, score, age=None, yrclass=10):
          self.name = name
          self.firstname = name.split()[0]
          try:
              self.lastname = name.split()[1]
          except:
              self.lastname = None
  
          self.score = score
          self.age = age
          self.yrclass = yrclass
      def yrup(self):
          self.age += 1
          self.yrclass += 1
  
  if __name__ == "__main__":
      db = shelve.open('people.dat')
      db['han'] = Person('Han Solo', 100, 37)
      db['luke'] = Person('Luke Skywalker', 83, 26)
      db['chewbacca'] = Person('Chewbacca', 100, 90901)
  </code></pre>
  
  <p>So using this I can call out a single variable like:</p>
  
  <pre><code>print db['luke'].name
  </code></pre>
  
  <p>But if I wanted to print all variables, I'm a little lost.</p>
  
  <p>If I run:</p>
  
  <pre><code>f = db['han']
  dir(f)
  </code></pre>
  
  <p>I get:</p>
  
  <pre><code>['__doc__', '__init__', '__module__', 'age', 'firstname', 'lastname', 'name', 'score', 'yrclass', 'yrup']
  </code></pre>
  
  <p>But I want to be able to print the actual data of those.</p>
  
  <p>How can I do this?</p>
  
  <p>Thanks in advance!</p>