[Python-ideas] Default return values to int and float
Bruce Leban
bruce at leapyear.org
Wed Oct 5 04:55:00 CEST 2011
More information about the Python-ideas mailing list
Wed Oct 5 04:55:00 CEST 2011
- Previous message: [Python-ideas] Default return values to int and float
- Next message: [Python-ideas] Default return values to int and float
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On Mon, Oct 3, 2011 at 11:58 PM, David Townshend <aquavitae69 at 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. :-) -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.python.org/pipermail/python-ideas/attachments/20111004/9a5afe57/attachment.html>
- Previous message: [Python-ideas] Default return values to int and float
- Next message: [Python-ideas] Default return values to int and float
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-ideas mailing list