[Python-ideas] Null coalescing operator
Arek Bulski
arek.bulski at gmail.com
Fri Sep 9 16:01:44 EDT 2016
Sometimes I find myself in need of this nice operator that I used back in
the days when I was programming in .NET, essentially an expression
>>> expr ?? instead
should return expr when it `is not None` and `instead` otherwise.
A piece of code that I just wrote, you can see a use case:
def _sizeof(self, context):
if self.totalsizeof is not None:
return self.totalsizeof
else:
raise SizeofError("cannot calculate size")
With the oprator it would just be
def _sizeof(self, context):
return self.totalsizeof ?? raise SizeofError("cannot calculate
size")
pozdrawiam,
Arkadiusz Bulski
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20160909/36d1dadd/attachment.html>
More information about the Python-ideas
mailing list