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:
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
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
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.
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
: 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
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
@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
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
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
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
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
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
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
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,
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
: 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
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
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')
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 =
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 =
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
22 matches
Mail list logo