This is probably a really novice question, so forgive me.
If I know the name of an instance/variable - let's say I have a string called "variable_name" and a variable with the same name, how would I go about writing a piece of code that takes that string and converts it into something I can actually use and use class methods on, etc? Is that a thing that can happen at all?
Edit: Added some code to better articulate my question. I've got a code setup kind of like this (simplified for space):
class Class_Name:
count = 0
def __init__(self, foo, bar):
self.__class__.count += 1
self.foo = foo
self.bar = bar
def find_variable_name(class_name, number):
variable_name = "variable" + str(number)
return variable_name
variable1 = Class_Name("foo", "bar")
variable2 = Class_Name("foo2", "bar2")
variable3 = Class_Name("foo3", "bar3")
for instances in range(Class_Name.count):
print (find_variable_name(Class_Name, instances+1).foo)
This would give me the error "AttributeError: 'str' object has no attribute 'foo'" - how would I turn the object from a string to something I can work with?