I'm trying to bind a variable to a specific list within a class at runtime. The snippet below works, but I'd like to have the class name in the eval expression instead of the variable. i.e. the equivalent of:
mybin = 'bin2'
eval(foo.mybin)
which obviously won't work... but I can't seem to figure out the syntax after various incarnations of trying to glue "foo' and "mybin' together.
class A:
bin1 = [3,6,9]
bin2 = [12,14,25]
foo = A()
mybin = 'foo.bin2'
for bin in eval(mybin):
print bin
outputs:
12
14
25