if Request("something") == None: doesn't work
Oliver Fromme
olli at secnetix.de
Thu May 13 10:19:04 EDT 2004
John Roth <newsgroups at jhrothjr.com> wrote:
> "Sam Sungshik Kong" <ssk at chol.nospam.net> wrote:
> >
> > if Request("something") == None:
> > Response.Write("")
> > else:
> > Response.Write(Request("something"))
>
> [...]
> 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.
Furthermore, in Python the result of a boolean operator is
the value of the operand that has been evaluated last.
So, the above if...else construct could be reduced to this
simple (and very readable) line:
Response.Write(Request("something") or "")
Of course that assumes that the Request() really returns
None, not a string with content "None".
Best regards
Oliver
--
"To this day, many C programmers believe that 'strong typing'
just means pounding extra hard on the keyboard."
-- Peter van der Linden
More information about the Python-list
mailing list