I have the next situation. The goal of the following method is to return the object created from the incoming string. So I have:
class Situation(Generator):
If I understood you correctly, you want to create the Situation object from Generator's createsituation method. So you need the appropriate constructor in Situation class with passed string as an argument. Little changes in your code will achieve this:
class Situation(object):
def __init__(self, string):
print string
class Generator(object):
def createsituation(self, stringsituation="situation"):
return Situation(stringsituation)
g = Generator()
sitObj = g.createsituation("new_situation") # prints "new_situation" from Situation constructor