On Jan 18, 9:36 am, Paul Rubin <http://phr...@nospam.invalid> wrote: > Steven D'Aprano <st...@remove-this-cybersource.com.au> writes: > > def foo(self, x, y=None): > > if y is None: > > y = self.a > > > I don't find that clumsy in the least. I find it perfectly readable and a > > standard idiom. > > That has the same problem as the earlier version. If the person > passes None, they get self.a. I prefer: > > sentinel = object() > ... > > def foo(x, y=sentinel): > if y is sentinel: > y = self.a
It is too bad that it is so much work to detect whether 'y' was passed in the function call directly. However, sentinel is just as good (or nearly); at worst, you need one sentinel per argument per function, which is possible to create, which has a specific meaning. If you are making systematic function calls, e.g. with a dictionary or list, you can just use the sentinel in the dictionary. -- http://mail.python.org/mailman/listinfo/python-list