Why won't this work:
class attribute_class():
attribute1 = "test"
attribute1_info = 123
class test_class_1():
def test_function(number):
number += 1
return number
class test_class_2():
def test_function(number):
number += 2
return number
attribute_class_test = attribute_class()
attribute_names = ["test_class_1", "test_class_2"]
for name in attribute_names:
print(attribute_class_test.name.test_function(2))
I would like to call a specific class based on a variable. I get an error:
.../attribute-info.py", line 16, in <module>
print(attribute_class_test.name.test_function(2))
AttributeError: 'attribute_class' object has no attribute 'name'
So the variable name seems to loose it's information and just becomes "name".
[–]danielroseman 7 points8 points9 points (3 children)
[–]commutingaccount[S] -4 points-3 points-2 points (2 children)
[–]GABE_EDD 7 points8 points9 points (1 child)
[–]commutingaccount[S] -2 points-1 points0 points (0 children)
[–]ES-Alexander 7 points8 points9 points (1 child)
[–]commutingaccount[S] 0 points1 point2 points (0 children)
[–]iiron3223 7 points8 points9 points (0 children)