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

2009-08-14 Thread Alexander Kozlovsky
Jeff McAninch wrote: I very often want something like a try-except conditional expression similar to the if-else conditional. I think it may be done currently with the help of next function: def guard(func, *args): try: return func() except Exception, e:

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

2009-08-10 Thread Dj Gilcrease
I figure I would write up the PEP draft, I have never tried writing a pep before, but i did read PEP 1 and tried to follow it's formating guides. If there are no additions to the idea, then it seems there just needs to be a consensus on the syntax before submitting it to the peps list I posted

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

2009-08-08 Thread Stephen J. Turnbull
Steven D'Aprano writes: It's not immediately obvious to me why the last expression should be given that privileged rule. Why not the first expression? Or the second, for that matter. So find a large body of Lisp code and run grep -r prog1 | wc, grep -r prog2 | wc, and grep -r progn | wc on

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

2009-08-08 Thread Xavier Morel
On 8 Aug 2009, at 08:02 , Steven D'Aprano wrote: On Fri, 7 Aug 2009 08:22:14 pm Kristján Valur Jónsson wrote: Unless I am very much mistaken, this is the approach Ruby takes. Everything is an expression. For example, the value of a block is the value of The last expression in the block.

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

2009-08-07 Thread Jeff McAninch
Should be legal, right?, since syntax would be expression except expression if exception Dino Viehland wrote: On option 1 is this legal then? x = float(string) except float('nan') if some_check() else float('inf') if ValueError Thinking more about the syntax options: if P.J.'s if Option

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

2009-08-07 Thread Kristján Valur Jónsson
: 6. ágúst 2009 10:25 To: python-dev@python.org Subject: Re: [Python-Dev] (try-except) conditional expression similar to (if-else) conditional (PEP 308) Wouldn't it be smarter to fix the issue once and for all by looking into making Python's compound statements (or even all statements

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

2009-08-07 Thread MRAB
Jeff McAninch wrote: Should be legal, right?, since syntax would be expression except expression if exception Dino Viehland wrote: On option 1 is this legal then? x = float(string) except float('nan') if some_check() else float('inf') if ValueError Thinking more about the syntax

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

2009-08-07 Thread ilya
@python.org] On Behalf Of Xavier Morel Sent: 6. ágúst 2009 10:25 To: python-dev@python.org Subject: Re: [Python-Dev] (try-except) conditional expression similar to (if-else) conditional (PEP 308) Wouldn't it be smarter to fix the issue once and for all by looking into making Python's

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

2009-08-07 Thread Michael Foord
to confuse K -Original Message- From: python-dev-bounces+kristjan=ccpgames@python.org [mailto:python-dev-bounces+kristjan=ccpgames@python.org] On Behalf Of Xavier Morel Sent: 6. ágúst 2009 10:25 To: python-dev@python.org Subject: Re: [Python-Dev] (try-except) conditional expression

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

2009-08-07 Thread Alex Martelli
2009/8/7 Kristján Valur Jónsson krist...@ccpgames.com: Unless I am very much mistaken, this is the approach Ruby takes. Everything is an expression.  For example, the value of a block is the value of The last expression in the block. I've never understood the need to have a distinction

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

2009-08-06 Thread Nick Coghlan
P.J. Eby wrote: At 05:59 PM 8/5/2009 -0700, Raymond Hettinger wrote: [Jeffrey E. McAninch, PhD] I very often want something like a try-except conditional expression similar to the if-else conditional. An example of the proposed syntax might be: x = float(string) except float('nan') or

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

2009-08-06 Thread Dj Gilcrease
On Thu, Aug 6, 2009 at 4:47 AM, Nick Coghlanncogh...@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

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

2009-08-06 Thread Xavier Morel
On 6 Aug 2009, at 00:22 , Jeff McAninch wrote: I'm new to this list, so please excuse me if this topic has been discussed, but I didn't see anything similar in the archives. I very often want something like a try-except conditional expression similar to the if-else conditional. I fear this

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

2009-08-06 Thread MRAB
Nick Coghlan wrote: P.J. Eby wrote: At 05:59 PM 8/5/2009 -0700, Raymond Hettinger wrote: [Jeffrey E. McAninch, PhD] I very often want something like a try-except conditional expression similar to the if-else conditional. An example of the proposed syntax might be: x = float(string) except

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

2009-08-06 Thread Eric Pruitt
What about catching specific error numbers? Maybe an option so that the dictionary elements can also be dictionaries with integers as the keys: filedata = try_3(open, randomfile, except = { IOError, {2: None} } ) If it isn't found in the dictionary, then we raise the error. On Thu, Aug 6,

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

2009-08-06 Thread Russell E. Owen
In article d28975e8-6706-4515-9c9e-fb7f90775...@masklinn.net, Xavier Morel catch-...@masklinn.net wrote: On 6 Aug 2009, at 00:22 , Jeff McAninch wrote: I'm new to this list, so please excuse me if this topic has been discussed, but I didn't see anything similar in the archives. I

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

2009-08-06 Thread Dino Viehland
: Thursday, August 06, 2009 3:48 AM To: P.J. Eby Cc: python-dev@python.org; Jeff McAninch Subject: Re: [Python-Dev] (try-except) conditional expression similar to (if-else) conditional (PEP 308) P.J. Eby wrote: At 05:59 PM 8/5/2009 -0700, Raymond Hettinger wrote: [Jeffrey E. McAninch, PhD] I very

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

2009-08-06 Thread Dino Viehland
MRAB wrote: Dino Viehland wrote: On option 1 is this legal then? x = float(string) except float('nan') if some_check() else float('inf') if ValueError Well, is this is legal? try: x = float(string) except some_check(): x = float('nan') except

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

2009-08-06 Thread MRAB
Dino Viehland wrote: MRAB wrote: Dino Viehland wrote: On option 1 is this legal then? x = float(string) except float('nan') if some_check() else float('inf') if ValueError Well, is this is legal? try: x = float(string) except some_check(): x = float('nan')

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

2009-08-05 Thread Jeff McAninch
I'm new to this list, so please excuse me if this topic has been discussed, but I didn't see anything similar in the archives. I very often want something like a try-except conditional expression similar to the if-else conditional. An example of the proposed syntax might be: x =

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

2009-08-05 Thread P.J. Eby
At 05:59 PM 8/5/2009 -0700, Raymond Hettinger wrote: [Jeffrey E. McAninch, PhD] I very often want something like a try-except conditional expression similar to the if-else conditional. An example of the proposed syntax might be: x = float(string) except float('nan') or possibly x =

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

2009-08-05 Thread Jeff McAninch
Raymond Hettinger wrote: If accepted, this would also solve the feature requests for various functions to have default arguments. For example: x = min(seq) except ValueError else 0 # default to zero for empty sequences It would also be helpful in calculations that have algebraic