title: python: creating instance from variable name
body: <p>***EDIT2: Sorry about the broken code. Here is working code which illustrates the same issue:</p>
  
  <pre><code>class bead():
      def printmsg(a):
          print('test message')
  
  chain1=bead()
  x='chain1'
  eval(x + '.printmsg()')
  </code></pre>
  
  <p>***EDIT: Thank you gnibbler for answering the original question. Here's a better worded version of my question:</p>
  
  <pre><code>class bead():
      def msg():
          print('test message')
  
  x='chain1'
  y='bead1'
  
  eval(x + '.' + y + '=bead()')
  
  chain1.bead1.msg()
  </code></pre>
  
  <p>output:
  'test message'</p>
  
  <p>What's a better way to do that?</p>
  
  <p>Original question:</p>
  
  <p>script:</p>
  
  <pre><code>class testClass():
      test1='test1 text'
  
  x='testClass'
  y='test1'
  
  eval(x + '.' + y)
  </code></pre>
  
  <p>output:
  'test1 text'</p>
  
  <p>Is there a better way of doing this?</p>
  
  <p>***EDIT: getattr() works for pulling the information from the class. Thank you gnibbler. Let me change the question a little bit though:</p>
  
  <p>what could I use instead of:</p>
  
  <p>x='chain1'
  y='mol1'</p>