answers.py v0.0.1 - source
bearophileHUGS at lycos.com
bearophileHUGS at lycos.com
Thu Dec 28 08:55:21 EST 2006
Marc 'BlackJack' Rintsch:
You give lot of comments and I agree with most of them.
> One idiom to solve this is:
> def __init__(self, answers=None):
> self.answers = answers or dict()
I suggest to avoid such usage of or/and (expecially for newbies), that
is triky and can produce bugs, and to use a more explicit if:
def __init__(self, answers=None):
if answers is None:
self.answers = {}
else:
self.answers = answers
If you are sure you can use 2.5+ (the enclosing of the if is optional,
but helps readability):
def __init__(self, answers=None):
self.answers = ({} if answers is None else answers)
Bye,
bearophile
More information about the Python-list
mailing list