Good code patterns in Python

Curly Joe woooee at yahoo.com
Tue Jul 1 19:56:16 EDT 2003


In your original example,

if some_condition:
some_name = some_value
else:
some_name = other_value

the default value is with the else statement.  It is
always some_name = other_value as a default whenever
some_condition isn't met, so in the second part, your
code should read:

some_name = other_value
if some_condition:
some_name = some_value

not vice versa as you had it - if I am interpreting it
correctly.
some_name = some_value
if not some_condition:
some_name = other_value

Either way, you or I are making a mistake with your
code, while using an if/else doesn't produce this type
of misunderstanding IMHO.  Obviously, clarity is in
the eye of the beholder though, and so there is, are,
and will always be differences, and this is a good
thing.


__________________________________
Do you Yahoo!?
SBC Yahoo! DSL - Now only $29.95 per month!
http://sbc.yahoo.com





More information about the Python-list mailing list