I have a class, trying to instantiate another class, based off of a variable name passed to it. It is complaining that 'str' object is not callable. What is the proper way to do this?
def MyClass:
def __init__(self, otherName):
self.other = otherName()
EDIT: Here is the entirety of my code, is there anything I should do differently? Is eval evil in Python?
#!/usr/bin/python
class Model:
def get_post(self, id):
# Would query database, perhaps
return {"title": "Python :: Test Page", "body": "Test page using Python!"}
class Controller:
def __init__(self, viewName):
self.model = Model()
self.view = viewName()
def main(self):
post = self.model.get_post(1)
self.view.display(post)
class View:
def header(self, item):
print "Content-type: text/html\r\n\r\n"
print "<html>"
print "<head>"
print "<title>%(title)s</title>" % item
print "</head>"
print "<body>"
def footer(self, item):
print "</body>"
print "</html>"
class Blog(View):
def display(self,item):
View.header(self,item)
print "<p>%(body)s</p>" % item
View.footer(self,item)
c = Controller(Blog)
c.main()