True

Paul Watson pwatson at redlinec.com
Sun Oct 19 10:17:12 EDT 2003


"John Roth" <newsgroups at jhrothjr.com> wrote in message
news:virjpa532l4117 at news.supernews.com...
>
> "Daniel Klein" <danielk at aracnet.com> wrote in message
> news:fucrivcvd2mel7k51ij1hktb55gqnmk9ic at 4ax.com...
> > In Python 2.2 I use to have
> >
> > true = (1 == 1)
> > false = not true
> >
> > This was at the recommendation of someone on this list some time ago.
> > The reason (if I remember correctly) was that setting
> >
> > true = 1
> > false = 0
> >
> > were not true booleans.
>
> There were no true booleans in 2.2 and earlier. Whoever recommended
> that didn't know what he was talking about. There was no difference.
>
> > Now the expression (1 == 1) returns 'True', and caused a bug in my
> > code. So my question is what is the proper method for setting booleans
> > in 2.3?
>
> I presume what broke your code was depending on the return from
> either str() or repr(), or the % operator. That was, unfortunately, one
> of the incompatibilites between 2.2 and 2.3.
>
> In 2.3, Boolean is a subtype of Int, and has two values: True and False.
> Both of these are built in constants, so just use them. That's what
they're
> for. For most purposes, the are the same as 1 and 0, except for what they
> return from str() and repr(), and how they get formatted with %.
>
> John Roth
>
> >
> > Really confused,
> >
> > Daniel Klein

Then, what is the best way to write boolean operations for Python 2.1 so
that it will be as 2.3+ ready as possible?

Should we just use 0 and 1?

Until the vendor of the tool we are using delivers a more recent version of
Python with the product, we must produce 2.1 compatible code.

Thanks.






More information about the Python-list mailing list