Default if none

Chris Rebert clp2 at rebertia.com
Thu Apr 29 22:30:44 CEST 2010


On Thu, Apr 29, 2010 at 12:01 PM, Michel Claveau - MVP
<enleverLesX_XXmcX at xmclavxeaux.com.invalid> wrote:
> Hi!
>
>> print x or y or z
>> If none of the potential values are considered boolean false
>
> But :
>  a=None
>  b=False
>  c=None
>  print a or b or c
>  > None

Consider:

def read_default_from_config(cfg_file):
    #pseudocode
    if not_specified_in(cfg_file):
        return None
    return read_value_from(cfg_file)

a = None
b = read_default_from_config("1.cfg")
c = read_default_from_config("2.cfg")

print a or b or c

Now, what happens when the user puts a default of 0 in 1.cfg? This was
my intended point.

Cheers,
Chris
--
http://blog.rebertia.com



More information about the Python-list mailing list