How safe is this way of getting a default that allows None?

Tim Chase python.list at tim.thechases.com
Sun Dec 25 20:14:29 EST 2011


On 12/25/11 18:49, Dan Stromberg wrote:
> How safe is this?  I like the idea.
>
> UNSPECIFIED = object()
>
> def fn(x, y=UNSPECIFIED):
>     if y is UNSPECIFIED:
>        print x, 'default'
>     else:
>        print x, y

safe?  It's idiomatic :)

-tkc





More information about the Python-list mailing list