if Request("something") == None: doesn't work
John Roth
newsgroups at jhrothjr.com
Wed May 12 18:04:10 EDT 2004
"Sam Sungshik Kong" <ssk at chol.nospam.net> wrote in message
news:AVsoc.47661$FI7.6868 at newssvr29.news.prodigy.com...
> Hello!
>
> I use Python for ASP programming.
> I found something weird.
>
> Response.Write(Request("something"))
> It draws "None" when there's no value for something.
> Actually I expect "" instead of "None".
>
> So I changed it like
> if Request("something") == None:
> Response.Write("")
> else:
> Response.Write(Request("something"))
>
> Strangely, the result of comparison is False.
>
> if str(Request("something")) == "None":
> works!
>
> Also,
> if len(Request("something")) == 0:
> works!
>
> What's wrong?
Darned if I know. However, there are two comments.
1. The standard way to check for None is to use the
"is" operator, not the "==" operator. You might try
that. The equals test ought to work, though.
2. However, the even easier way to do it is not to do
a check at all, but simply rely on the fact that both None
and the null string act like False in an if statement. In
other words, just remove the "== None" and see what
happens.
John Roth
>
> ssk
>
>
More information about the Python-list
mailing list