call to function by text variable

Jan Schilleman jan.schilleman at xs4all.nl
Sun Mar 25 18:53:55 EDT 2007


Hi,

try this:
func = getattr(operations, ["Replace", "ChangeCase", "Move"][n])

HTH,
Jan

"ianaré" <ianare at gmail.com> schreef in bericht 
news:1174862186.134912.117270 at p15g2000hsd.googlegroups.com...
> yeah the subject doesn't really make sense does it?
>
> anyway want I want to do is this:
> if n == 1:
>
>    self.operations.insert(pos, operations.Replace.Panel(self, main))
>
> elif n == 2:
>
>    self.operations.insert(pos, operations.ChangeCase.Panel(self,
> main))
>
> elif n == 3:
>
>    self.operations.insert(pos, operations.Move.Panel(self, main))
>
> As you can see all the different functions have the same variables, so
> it would be easier if I could just make a list and use that.
>
> like this:
>
>
> list = ["Replace", "ChangeCase", "Move"]
> textVariable = list[n]
> self.operations.insert(pos, operations.[textVariable].Panel(self,
> main))
>
> Is something sort of like that possible?
>
>
> TIA
>
> -- 
> http://mail.python.org/mailman/listinfo/python-list
> 






More information about the Python-list mailing list