title: Pythonic way to avoid a mountain of if...else statements?
body: <p>This has come up several times recently and I'd like to deal with it better than I have been: I have a series of attributes that I'm cross referencing between an object and a dictionary.  If the value is different between them, I want to set the object.attribute to the dictionary['attribute'] value.  I also want to keep track of what's getting changed.</p>
  
  <p>Now, my first thought is to just use an if else statement for every attribute, but after writing a few of these it's apparent that I'm re-writing the same code again and again.  There has to be a DRY way to do this, where I specify only the parts that are changing every time, and then loop through all the attributes.</p>
  
  <p>In production code, there are 15 different attributes, but my example below will just use 2 for simplicity.  I have some idea about how to do this in a clever way, but I'm missing the final step of actually setting the object.attribute equal to the dictionary['attribute'] value.</p>
  
  <pre><code># Simulated data setup - not under my control IRL
  class someClass:
      def __init__(self, name, version):
          self.name = name
          self.version = version
  
  objA = someClass('Test1','1.1')        
  dictA = {'name':'Test1','revision':'1.2'}
  
  # My code below        
  
  # option 1 - a series of for loops
  def updateAttributesSimple(obj, adict, msg):
      if obj.name == adict['name']:
          msg.append('Name is the same')
      else:
          msg.append('Name was updated from %s to %s' % (obj.name, adict['name']))
          obj.name = adict['name']
  
      if obj.version == adict['revision']:
          msg.append('Version is the same')
      else:
          msg.append('Version was updated from %s to %s' % (obj.version, adict['revision']))
          obj.version = adict['revision']        
  
  # option 2 - trying to be clever about this
  def updateAttributesClever(obj, adict, msg):
      attributeList = (('Name', obj.name, adict['name']),
                       ('Version', obj.version, adict['revision']))
  
      for valTuple in attributeList:
          if valTuple[1] == valTuple[2]:
              msg.append('%s is the same' % (valTuple[0]))
          else:
              msg.append('%s was updated from %s to %s' % (valTuple[0], valTuple[1], valTuple[2]))
              # code to set valTuple[1] = valTuple[2] goes here, but what is it?
              # valTuple[1] = valTuple[2] attempts to set the desired value to a string, rather than the attribute of obj itself            
  
  
  msg = ['Updating Attributes simple way:']
  updateAttributesSimple(objA, dictA, msg)
  print '\n\t'.join(msg)
  
  #reset data
  objA = someClass('Test1','1.1')        
  dictA = {'name':'Test1','revision':'1.2'}
  
  msg = ['Updating Attributes clever way:']
  updateAttributesClever(objB, dictB, msg)
  print '\n\t'.join(msg)
  </code></pre>
  
  <p>The idea being that this way, whenever I need to add another attribute, I can just update the list of attributes being inspected and the rest of the code is already written.  What's the Pythonic way to accomplish this?</p>