True inconsistency in Python

Terry Reedy tjreedy at udel.edu
Tue Nov 18 19:26:43 EST 2003


"Ron Adam" <radam2 at tampabay.rr.com> wrote in message
news:83bjrvcm92o6l2gte1nbehrpvofm0r5i88 at 4ax.com...

> I believe the words 'True' and 'False' need to be treated the same
as
> the digits 1, 2, 3, ...  The values of the digits do not change.
We
> depend on them not changing.
> True should always evaluate to True also.
> So we can depend on it as well.
> This is my opinion,  you don't have to agree with it.

Others have also proposed that None, True, and False be made keywords.
We'll see how far Guido goes in 3.0.  I do not think even he really
knows.

> >> It looks to me that 'True' in python is a combination of the
boolean
> >> binary logic of 1 or 0, and as an "exists" test of 0 or not 0.
[me]
> >I do not understand this.  If you have a reference to 0, then 0
> >exists.  If you do not, then the 'existence' or not of an int with
> >value 0 is irrelevant.

> if x:   is a test to see if the value 0 does not exist in x.

Aha.  Got it.  Above, you are using 'exist' at a different level of
abstraction than I understood.  I was thinking of object or binding
existence, whereas you were speaking of value connotation.  Yes, if c
is a count of something, then 'if c:' tests for the positive existence
of at least one counted something.  Similarly for list L of
somethings, 'if L:' tests for the existence of at least one listed
something.

I consider this 'overloading' of conditional expressions to be one of
the great features of Python.  I now take it for granted.

> >> if  x exists:
> >> 'do something'
> >
> >Do you mean
> >if bound_to_something('x'): <do something>
> >?
> >
>
> Yes,  you understand.

Whoops, now you are agreeing with 'exist' as 'binding existence'.
Yes, this is a 'divergence' from your other sense of exist.

> Yes,  I noticed.   The reason I bring this up is in situations where
> you want to initialize a variable if it has not been defined yet,
but
> do not want to re initialize it if it's already been defined.

For just one variable, I might use

try: x
except NameError: x = 'value'

Terry J. Reedy






More information about the Python-list mailing list