I'm having trouble printing a method with a variable.
If I do print (pet.__str__()), it works as expected. However I'm trying to loop through the method using variables to replace "pet" with a variable. I'm then assigning it to a variable and trying to print it. When I print it, it literally prints the string pet.__str__() instead of calling the method. I'm not sure what I'm doing wrong. Here's a general overview of my code. Thanks
pet = Pet('Taz')
my_list = ["pet", "dog", "big_dog", "small_dog"]
my_string = ["animal_variable.__str__()", "animal_variable.kind", "animal_variable.color", "animal_variable.do_tricks()"]
sentence1 = []
sentence1 = my_string[0]
print (sentence1) #DEBUGGING*****************************************
print (sentence1.replace('animal_variable', my_list[0]))
print (type(sentence1))
*** HERE'S THE OUTPUT I GET *******
animal_variable.__str__()
pet.__str__(),
class 'str'
*** If I do this it works as expected, however this doesn't allow me to loop through different variables in my list
print (pet.__str__())
petis already variable - what other variable do you what to use ?pet.__str__()you should usestr(pet)- it is prefered method.evala string to get your variables?"pet.__str__()"is only string so don't expect that it will call a method.