On Dec 7, 9:37 am, Lars Johansen <[EMAIL PROTECTED]> wrote: > I have a function that looks like this: > > def Chooser(color): > > if color == "RED": > x = term.RED > elif color == "BLUE": > x = term.BLUE > elif color == "GREEN": > x = term.GREEN > elif color == "YELLOW": > x = term.YELLOW > elif color == "CYAN": > x = term.CYAN > elif color == "MAGENTA": > x = term.MAGENTA > return x > > Wouldn there been easier if I could just skip all the "*if's" and just > "return term.color", however this gives a syntax error, are there any > clever way to do this ? > -- > Lars Johansen <[EMAIL PROTECTED]>
"return getattr(term, color)" should do the trick. -- http://mail.python.org/mailman/listinfo/python-list