A library approach to the ternary operator

Gary Herron gherron at islandtraining.com
Fri Mar 21 23:12:45 EST 2003


>
> Another possibility along these sames lines is:
>
> # ternary module
> def select(test, iftrue, iffalse):
> 	if test:
> 		if callable(iftrue):
> 			return iftrue()
> 		else:
> 			return iftrue
> 	else:
> 		if callable(iffalse):
> 			return iffalse()
> 		else:
> 			return iffalse()
>

Please no!  Consider choosing one of two functions for later use:

  MouseFunc = isLeftHanded ? LeftMouseFunc : RightMouseFunc

These are callables, but I certainly don't want them called now.
Rather I want MouseFunc to be one or the other function (presumably to
ba called later).

Gary Herron







More information about the Python-list mailing list