On Mon, Oct 3, 2011 at 11:58 PM, David Townshend <aquavitae69@gmail.com> wrote:

A generalised try_convert method would be useful, but I think I would rather see a one-line version of the try statements, perhaps something like this:

    x = try float('some text') else 42 if ValueError

for parallelism with if/else operator I'd like

    float('some text') except ValueError then 42

which is equivalent to calling:

    def f():
      try:
        return float('some text')
      except ValueError
        return 42

For example,

    float(foo) except ValueError then None if foo else 0

or equivalently:

    float(foo) if foo else 0 except ValueError then None

Of course this requires a new keyword so the chances of this being added are slim.

--- Bruce
w00t! Gruyere security codelab graduated from Google Labs! http://j.mp/googlelabs-gruyere
Not to late to give it a 5-star rating if you like it. :-)