473,473 Members | 2,131 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

if Request("something") == None: doesn't work

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?

ssk
Jul 18 '05 #1
8 2201
Sam Sungshik Kong wrote:
if str(Request("something")) == "None":
works!

Also,
if len(Request("something")) == 0:
works!


Try Response.Write(repr(Request("something"))) to see if you are really
getting a None.
Jul 18 '05 #2
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

At 2004-05-12T17:12:00Z, "Sam Sungshik Kong" <ss*@chol.nospam.net> writes:
if Request("something") == None:
Have you tried:

if Request("something") is None:
if str(Request("something")) == "None":
Well, right. repr(None) == 'None'.
if len(Request("something")) == 0:
works!


That seems kinda strange, granted.
- --
Kirk Strauser
The Strauser Group
Open. Solutions. Simple.
http://www.strausergroup.com/
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (GNU/Linux)

iD8DBQFAonJC5sRg+Y0CpvERAvRPAJ0Uojjx9qMtOHKApnDMnt 3TxsL5ngCgnKWG
ejWI7Ycj5asnK9WsoWL11Eo=
=bL+r
-----END PGP SIGNATURE-----
Jul 18 '05 #3

"Sam Sungshik Kong" <ss*@chol.nospam.net> wrote in message
news:AV******************@newssvr29.news.prodigy.c om...
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

Jul 18 '05 #4
Thanks for the replies.

Based on the hints from the replies, I've tested some.

When there's no argument in the request,

Request("id") == None returns False
if Request("id"): returns True
str(Request("id")) returns "None"
repr(Request("id")) returns <COMObject<unknown>>

So my conclusion is that Request("id") is not None.
It's an object, str() of which is accidentally "None".
That confused me.

If it's not None, str(something) should not return "None".

ssk

"Sam Sungshik Kong" <ss*@chol.nospam.net> wrote in message
news:AV******************@newssvr29.news.prodigy.c om...
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?

ssk

Jul 18 '05 #5
Sam Sungshik Kong wrote:
If it's not None, str(something) should not return "None".


What about str("None")?
Jul 18 '05 #6
Quoth "Sam Sungshik Kong" <ss*@chol.nospam.net>:
....
| When there's no argument in the request,
|
| Request("id") == None returns False
| if Request("id"): returns True
| str(Request("id")) returns "None"
| repr(Request("id")) returns <COMObject<unknown>>
|
| So my conclusion is that Request("id") is not None.
| It's an object, str() of which is accidentally "None".
| That confused me.

It would confuse anyone. That's pretty bad.

Donn Cave, do**@drizzle.com
Jul 18 '05 #7
Sam Sungshik Kong wrote:
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".

You could make it easier on yorself and you convert your Request object
to a Python Dictionary instead.

http://www.mxm.dk/products/public/iisUtils

regards Max M
Jul 18 '05 #8
John Roth <ne********@jhrothjr.com> wrote:
"Sam Sungshik Kong" <ss*@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
Jul 18 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

32
by: James Curran | last post by:
I'd like to make the following proposal for a new feature for the C# language. I have no connection with the C# team at Microsoft. I'm posting it here to gather input to refine it, in an "open...
1
by: Bob Murdoch | last post by:
I just moved my website from a Win2000 server to a Win2003 server. On the old server, we would prompt for the user name and password via the WWW-Authenticate header, retrieve the Base64 values...
7
by: vvkl | last post by:
I have readed a example code from MSDN about FormsAuthenticationTicket calss, but there's a line I can't understand : 'strRedirect = Request;' What's the mean in which square brackets? Thank...
7
by: sami | last post by:
Hi I am trying to write a facebook application in python - I have been programming simple desktop applications till now and am not really familiar with web apps Pyfacebook is the wrapper for...
5
by: magix8 | last post by:
Hi, I have form GET method, example: index.asp?Type=1&Type=3&Type=4&.... So, I have something like this at the receiver side to retrieve multiple Type value and insert into tables.
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.