Permanent objects?
Bengt Richter
bokr at oz.net
Thu Dec 26 10:18:56 EST 2002
On Thu, 26 Dec 2002 01:16:46 -0800, Erik Max Francis <max at alcyone.com> wrote:
[...]
>That's why when you hear talk about where people want to have optional
>arguments that could _also be None_, they talk about making _another_
>unique sentinel object, usually a private one to the class:
>
> class C:
> _sentinel = object() # or whatever gets you a unique object
> def f(self, some, other=_sentinel):
> if other is _sentinel:
Nit: you'll get an undefined global ref unless you use
if other is self._sentinel: # ( C._sentinel possible, but would depend on global C)
> ... # handle the case where other wasn't specified
> ... # handle the normal case, but None is a valid value
>
>The test with is (not ==) is important here, because I want to make sure
>it's _that object_, not merely an object that tests equal to it. In
>fact you _don't_ want someone pretending
Regards,
Bengt Richter
More information about the Python-list
mailing list