Ricardo Aráoz wrote: > Kent Johnson wrote: >> Andy Cheesman wrote: >>> for thing in ["top", "right", "bottom", "left"]: >>> eval("self." + thing).append("fish") >> You don't need to use eval() here, use getattr() instead: >> getattr(self, thing).append('fish') >> > > What if you want to do : > MyObj = 1 > myStr = 'MyObj' > eval('MyObj') = 125
Usually a dictionary is the right solution, instead of a named variable. values = {'MyObj' : 1} values[myStr] = 125 Kent _______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor