For review: PEP 308 - If-then-else expression
dale at riverhall.NOTHANKS.co.uk
Sat Feb 8 21:55:35 CET 2003
Paul Rubin <phr-n2003b at NOSPAMnightsong.com> wrote:
>Dale Strickland-Clark <dale at riverhall.NOTHANKS.co.uk> writes:
>> >An example:
>> > def get_arg(self, default=1):
>> > """Return any prefix argument that the user has supplied,
>> > returning `default' if there is None. `default' defaults
>> > (groan) to 1."""
>> > if self.arg is None:
>> > return default
>> > else:
>> > return self.arg
>> Yuck! An pointless function that boils down to:
>> self.arg or default
>> in current parlance.
> self.arg or default
>will incorrectly give the default, if self.arg is 0 or the empty
>string or an empty dict, etc. A conditional expression is really the
>right thing here.
Yup. I goofed.
Riverhall Systems Ltd
More information about the Python-list