[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [pygame] Question - Comparing strings



On Thu, Sep 4, 2008 at 10:15 AM, kschnee <kschnee@xxxxxxxxxx> wrote:
> >> if WordListFile == "default" or "default" or "Default" or "d" or "D":
> >
> > This does not do what you think it does.  What you want is this:
> > if word_list_file.lower() in ("default", "d"):
>
> By way of further explanation, what Python is doing with the right side of
> the original line is selecting the first item that evaulates to True. Any
> string other than "" is True, so the result is "default". So, the line
> works out to 'if WorldListFile == "default"', and the effect would be that
> the other options like "D" won't count as recognized alternatives.
>

Actually, no. The effect of the above line is that it will always
evaluate to true. It is the equivalent of this:

if (word_list_file == "default") or "Default" or "d" or "D":

which is of course always true since any non-empty string evaluates to True.
 Hugo