function argument dependent on another function argument?

andrew cooke andrew at acooke.org
Sun Jan 18 13:42:23 EST 2009


>     sentinel = object()
>     ...
>
>     def foo(x, y=sentinel):
>       if y is sentinel:
>           y = self.a

it just struck me you could also do:

     def foo(self, x, *y_args)
       y = y_args[0] if y_args self.a

which more directly checks whether an argument was passed, but has the
downside of making the method signature less clear in the declaration.

andrew



More information about the Python-list mailing list