Jaki jest najlepszy sposób na utworzenie obiektu Pythona, gdy implementacja klasy jest przechowywana w łańcuchu?
Jaki jest najlepszy sposób na dynamiczne tworzenie instancji obiektu Pythona, gdy masz tylko klasę Pythona zapisaną jako ciąg?
W tle pracuję w środowisku Google Application Engine i chcę mieć możliwość dynamicznego ładowania klas z wersji tekstowej klasy.
problem = “1,2,3,4,5”
solvertext1 = “””class solver:
def solve(self, problemstring):
return len(problemstring) “””
solvertext2 = “””class solver:
def solve(self, problemstring):
return problemstring[0] “””
solver = #The solution code here (solvertext1)
answer = solver.solve(problem) #answer should equal 9
solver = #The solution code here (solvertext2)
answer = solver.solve(problem) # answer should equal 1