Ronny Mandal wrote: > Assume we have a class Foo, and instance called bar. > > a variable called baz1 has the value 3.0, baz2 is uninitialized > > Is there a way of reflecting the variable with such syntax: > > print bar[<var_index>], where var_index is a number representing > internal index. > > bar[<var_index>] = 4.2. #Setting baz2 to 4.2 > > Thanks and regards, > > Ronny Mandal
I can't figure out why did you tell us that baz1 has value of 3.0? What does that have to do with anything? It is also uncloear how you think that setting something inside bar class instance could possibly create a variable called baz2? Python doesn't have a concept of "unitialized" variables. Before they are initialized they simply don't exist. Variables in Python aren't buckets, variables are pointers to information. I think we need more information about what you are trying to accomplish before we can help. Just as a wild guess I think you want a dictionary. vdict=['baz1': 3.0, 'baz2': None} vdict['baz2']=4.2 print vdict['baz2'] if you insist on an index you can do: vars=['baz1','baz2'] print vdict[vars[2]] I'm REALLY guessing here, so I don't know if I'm helping. -Larry Bates -- http://mail.python.org/mailman/listinfo/python-list