Setting a variable to the name of a class and calling a function from that class
<p>Is there a way to set a variable to a string, and then use that variable to call a function from a class with the same name of that variable?</p>

<p>For example:</p>

<pre><code>class Foo(object):
    def printer(self):
        print "Hello."

Bar = Foo()
var = 'Bar'
</code></pre>

<p>When I then try to call var.printer(), I get the error:</p>

<pre><code>AttributeError: 'str' object has no attribute 'printer'
</code></pre>

<p>Which makes sense, but is there any way to call a class function in that manner, by using a variable with the same name as the class?</p>

<p>The reason I want to do this is so that I can have a set of individual variables, be able to adjust those variables, and then combine them into a string and call a function from a class with the same name as the string. For example:</p>

<pre><code>from random import randint    

x = 0
y = 0

class c00(object):
    def printname(self):
        print "c00"

class c01(object):
    def printname(self):
        print "c01"

choose_class = randint(0, 2)

if choose_class == 0:
    xstr = str(x)
    ystr = str(y)
    string = 'c' + xstr + ystr
    string.printname()

else:
    y += 1
    xstr = str(x)
    ystr = str(y)
    string = 'c' + xstr + ystr
    string.printname()
</code></pre>

<p>Is there any way to make this work?</p>
