For review: PEP 308 - If-then-else expression

Anders Hammarquist iko at cd.chalmers.se
Mon Feb 10 13:01:11 EST 2003


In article <mailman.1044815069.18670.python-list at python.org>,
Carlos Ribeiro  <cribeiro at mail.inet.com.br> wrote:
>On Saturday 08 February 2003 21:08, Janto Dreijer wrote:
>Most potential uses are to avoid some exception being thrown: testing on an 
>array index, avoiding a division by zero, negative square roots and so on.

But exceptions are cheap in Python, there is really no need to avoid
them (yes, I know this can be a difficult concept for someone coming
from the C++ world).

>For business applications it is also useful, because sometimes we do retrieve 
>values from external sources depending upon some condition. The meta-code 
>below shows the basic idea:
>
>  zip_code = (some_zip if (some_zip != None) else find_zip(some_address))

How is that simpler than

  zip_code = some_zip or find_zip(some_address)

which does exactly the same thing without new syntax?

/Anders

-- 
 -- Of course I'm crazy, but that doesn't mean I'm wrong.
Anders Hammarquist                                  | iko at cd.chalmers.se
Physics student, Chalmers University of Technology, | Hem: +46 31 88 48 50
G|teborg, Sweden.           RADIO: SM6XMM and N2JGL | Mob: +46 707 27 86 87




More information about the Python-list mailing list