How safe is this way of getting a default that allows None?
Dan Stromberg
drsalists at gmail.com
Sun Dec 25 19:49:56 EST 2011
How safe is this? I like the idea.
#!/usr/bin/python
UNSPECIFIED = object()
def fn(x, y=UNSPECIFIED):
if y is UNSPECIFIED:
print x, 'default'
else:
print x, y
fn(0, 1)
fn(0, None)
fn(0)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20111225/11c5d866/attachment-0001.html>
More information about the Python-list
mailing list