function argument dependent on another function argument?

andrew cooke andrew at acooke.org
Sun Jan 18 19:42:23 CET 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