title: Python: Concatenate two strings for getting a variable from a class
body: <p>I have a Python class , having some variables. The definition of the class is as follows:</p>
  
  <pre><code>class student:
      def __init__(self,name,rollno,DOB,branch):
         self.name=name
         self.rollno=rollno
         self.DOB=DOB
         self.branch=branch
         self.books=[]
         self.fines=[]
  </code></pre>
  
  <p>I am <strong>adding new attributes</strong> for a student , and need to store the corresponding values as well (for future use). This is done using the setattr method, and works fine.</p>
  
  <p>Code snippet:</p>
  
  <pre><code>setattr(student,"date_of_join",date())
  </code></pre>
  
  <p>Now I am approaching the problem as, if the user adds a new attribute (say, "<strong>date_of_join</strong>"), then I update a list (<strong>studattr</strong>), initially containing <strong>["name","rollno",DOB","branch","books","fines"]</strong>  to update the list of attributes. This means that the updated list will also have "date_of_join" now appended to it. </p>
  
  <p>Now if I want to <strong>access this list of attributes of a student Instance</strong>, then how do I do it? ( Since the records are dynamically updated, and let us suppose I have to access x.date_of_join, then how do I join the two strings? Is there anything similar to python's os.path.join, or rather linux's system call, (merging two strings)? )</p>
  
  <p>Problem:</p>
  
  <pre><code>for attribute in studattr:
      print attribute,x.attribute
  
  { This throws an Exception since the instance x has no variable or method named "attribute")  
  </code></pre>
  
  <p>PS: I tried using inspect,inspect.getmembers(x) as well as dirs(x), vars(x) ,(mentioned on stackoverflow), but it only gives me a list of variables/methods in main class body and not in <strong>init</strong>.</p>