For review: PEP 308 - If-then-else expression
Paul Moore
gustav at morpheus.demon.co.uk
Sat Feb 8 17:45:15 EST 2003
Carel Fellinger <carel.fellinger at chello.nl> writes:
> Other usage is probably like this:
>
> class MadeUp:
> def example(self, param1=None, param2=None, param3=None, param4=None):
> # zero is a valid value for all params
> self.param1 = param1 == None and some-default1 or param1
> self.param2 = param2 == None and some-default2 or param2
> self.param3 = param3 == None and some-default3 or param3
> self.param4 = param4 == None and some-default4 or param4
Um, why not just
def example(self, param1=default1, param2=default2, ...)
???
If you have to calculate the default at runtime, you could do
def example1(self, param1=None):
self.param1 = param1
if param1 is None: self.param1 = default1
but the full if/else statement version isn't that bad.
BTW, if you really have that many parameters all with
runtime-calculated defaults, and all optional, you should probably
consider changing your design...
It's another plausible use case, though. Just not plausible enough for
me.
Paul.
--
This signature intentionally left blank
More information about the Python-list
mailing list