title: How to access python objects with a dynamic object name?
body: <p>I have a question to one of my python scripts. I'm using the library untangle (<a href="https://github.com/stchris/untangle" rel="nofollow">https://github.com/stchris/untangle</a>) to import and convert xml config files into the main script.</p>
  
  <p>The problem: I have user informations in the config file for more than one user and I'm using this information in a loop. It works very well, but it makes the script very ugly due to the name of the generated objects from the xml file.</p>
  
  <p>Concrete this means I can't (or I just don't know how) change the name of the object I would like to use dynamic. </p>
  
  <p>The example code is below:</p>
  
  <pre><code>            if employee == 0:
                  if str(configobj.config.modes.employee.employee_1.name.cdata) != '':
                      display.drawtext(0,0,str(configobj.config.modes.employee.employee_1.name.cdata),"7x13B",255,255,255,True)
                      if str(configobj.config.modes.employee.employee_1.line1.cdata) != '':
                          display.drawtext(int(configobj.config.modes.employee.employee_1.line1['x']),
                                           int(configobj.config.modes.employee.employee_1.line1['y']),
                      if str(configobj.config.modes.employee.employee_1.line2.cdata) != '':
                          display.drawtext(int(configobj.config.modes.employee.employee_1.line2['x']),
                                           int(configobj.config.modes.employee.employee_1.line2['y']),
                      if str(configobj.config.modes.employee.employee_1.line3.cdata) != '':
                          display.drawtext(int(configobj.config.modes.employee.employee_1.line3['x']),
                                           int(configobj.config.modes.employee.employee_1.line3['y']))
                      displayimage = True
  
              elif employee == 1:
                  if str(configobj.config.modes.employee.employee_2.name.cdata) != '':
                      display.drawtext(0,0,str(configobj.config.modes.employee.employee_2.name.cdata),"7x13B",255,255,255,True)
                      if str(configobj.config.modes.employee.employee_2.line1.cdata) != '':
                          display.drawtext(int(configobj.config.modes.employee.employee_2.line1['x']),
                                           int(configobj.config.modes.employee.employee_2.line1['y']),
                      if str(configobj.config.modes.employee.employee_2.line2.cdata) != '':
                          display.drawtext(int(configobj.config.modes.employee.employee_2.line2['x']),
                                           int(configobj.config.modes.employee.employee_2.line2['y']),
                      if str(configobj.config.modes.employee.employee_2.line3.cdata) != '':
                          display.drawtext(int(configobj.config.modes.employee.employee_2.line3['x']),
                                           int(configobj.config.modes.employee.employee_2.line3['y']),
                      if str(configobj.config.modes.employee.employee_2.image.cdata) != '':
                          display.showimage(160,0,str(configobj.config.modes.employee.employee_2.image.cdata))
                      displayimage = True
  </code></pre>
  
  <p>And this is a lot of repeated code with a changing number. How can I improve this?</p>