Re: [Tutor] Issue with iterating within lists, objects and functions

2007-08-03 Thread Kent Johnson
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 : >

Re: [Tutor] Issue with iterating within lists, objects and functions

2007-08-03 Thread Andy Cheesman
Thanks for your help Kent The error was that I was trying to assign to a non-assignable reference as you highlighted. Everything works now Thanks Andy Kent Johnson wrote: > Andy Cheesman wrote: >> for thing in ["top", "right", "bottom", "left"]: >> eval("self." + thing).append("fish") > >

Re: [Tutor] Issue with iterating within lists, objects and functions

2007-08-03 Thread Kent Johnson
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') > eval("self." + thing +"_extra") > eval("self." + thing) = external_funct

[Tutor] Issue with iterating within lists, objects and functions

2007-08-03 Thread Andy Cheesman
Dear people, Sorry for the vague title, I'm struggling to define the problem but an example will be better/clearer. If I've a list of strings, which relate to objects(lists) elsewhere in my code, I can call list action fine within the loop but I was wondering how do I apply an external function as