conditional expressions (RE: Loop-and-a-half (Re: Curious assignment behaviour))

Andrew Dalke dalke at dalkescientific.com
Thu Oct 18 21:25:51 EDT 2001


Paul Rubin:
>"John Roth" <johnroth at ameritech.net> writes:
>> Many instances of this are already handled by the short-circuit
>> 'and' and 'or' operators.
>
>And that's supposed to be readable?

It can be

def f(dirname = None):
  dirname = dirname or os.eviron.get("MY_DIRNAME") or default_dirname

as compared to

  dirname = dirname ? dirname :
             (os.getenv("MY_DIRNAME") ? os.getenv("MY_DIRNAME") :
                 default_dirname);

                    Andrew
                    dalke at dalkescientific.com






More information about the Python-list mailing list