title: How to dynamically compose and access class attributes in Python?
body: <p>I have a Python class that have attributes named: date1, date2, date3, etc.</p>
  
  <p>During runtime, I have a variable i, which is an integer. </p>
  
  <p>What I want to do is to access the appropriate date attribute in run time based on the value of i.</p>
  
  <p>For example, </p>
  
  <p>if i == 1, I want to access myobject.date1</p>
  
  <p>if i == 2, I want to access myobject.date2</p>
  
  <p>And I want to do something similar for class instead of attribute.</p>
  
  <p>For example, I have a bunch of classes: MyClass1, MyClass2, MyClass3, etc. And I have a variable k.</p>
  
  <p>if k == 1, I want to instantiate a new instance of MyClass1</p>
  
  <p>if k == 2, I want to instantiate a new instance of MyClass2</p>
  
  <p>How can i do that?</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>I'm hoping to avoid using a giant if-then-else statement to select the appropriate attribute/class.</p>
  
  <p>Is there a way in Python to compose the class name on the fly using the value of a variable?</p>