A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2009-August/091055.html below:

[Python-Dev] (try-except) conditional expression similar to (if-else) conditional (PEP 308)

[Python-Dev] (try-except) conditional expression similar to (if-else) conditional (PEP 308) [Python-Dev] (try-except) conditional expression similar to (if-else) conditional (PEP 308)Dj Gilcrease digitalxero at gmail.com
Thu Aug 6 13:18:52 CEST 2009
On Thu, Aug 6, 2009 at 4:47 AM, Nick Coghlan<ncoghlan at gmail.com> wrote:
> Option 2:
>  x = float(string) except ValueError: float('nan')
>  op(float(string) except ValueError: float('nan'))
>
> This has the virtue of closely matching the statement syntax, but
> embedding colons inside expressions is somewhat ugly. Yes, lambda
> already does it, but lambda can hardly be put forward as a paragon of
> beauty.

+1 on this option as it resembles the standard try/except block enough
it would be a quick edit to convert it to one if later you realize you
need to catch more exceptions*

* I recommend NOT allowing multiple exceptions in this form eg
x = float(string)/var except ValueError, ZeroDivisionError, ...: float('nan')

as it will start to reduce readability quickly
More information about the Python-Dev mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4