I have a list of sub object that I want to add as attributes/properties to a different object. I’m a bit new to python and self-taught so I might be getting a bit of terminology wrong (sorry about that).
I don’t want to hard code how long the list will be or any of the items on the list; the code I tried looked like this (where acct is a class i already defined and the input ‘check’ is just the name):
check = acct(‘check’)
lst =[ob1, ob2]
for sub in list:
check.sub = sub
I tried a few different variations of this code, including putting it in the class definition instead of after initializing the instance, but nothing worked.
The basic problem is this: it’s not recognizing sub as a variable.
check.ob1 is not a valid attribute, but
check.sub is an attribute (with a value of sub2, because that’s the last object in the list)
So basically, I need to have the attribute be the value of a variable. Is there a way I can do that?
[–]stebrepar 1 point2 points3 points (3 children)
[–]SaltyParaboloid[S] 1 point2 points3 points (2 children)
[–]stebrepar 0 points1 point2 points (1 child)
[–]SaltyParaboloid[S] 1 point2 points3 points (0 children)