[Python-ideas] "or raise" syntax
Ethan Furman
ethan at stoneleaf.us
Thu Oct 30 16:13:42 CET 2014
On 10/30/2014 08:03 AM, Javier Dehesa wrote:
>
> This happens to me with some frequency:
>
> result = f(args)
> if not result: # of "if result is None:"
> raise Exception(...)
>
> What if I could just say?
>
> result = f(args) or raise Exception(...)
Seems like a decent idea, but you can already have most of that:
result = f(args) or raise_exc(ValueError, 'args must be ...')
and then have 'raise_exc' do the exception raising work.
--
~Ethan~
More information about the Python-ideas
mailing list