views:

57

answers:

2

Perhaps I am just crazy or missing something really basic. Why would this happen?

If I use this url

index.cgi?mode=pos&pos_mode=checkout&0_name=Shampoo&0_type=Product&0_price=4.50&0_qty=1&0_total=4.50

which runs this code

form = cgi.FieldStorage()

for key in form.keys()
    print key

    if re.search("name", key):
        print "Found name."

The result prints

mode

If I remove the re.search() it prints all the keys. Why?

I searched stackoverflow and google before I posted but I didn't come up with anything. Thanks in advance.

+1  A: 

Perhaps you get an error? Try checking types of all keys or anything you suspect could be wrong.

Armandas
+2  A: 

Are you getting an exception? Check your server logs. Have you done:

import re

at the top of the script? Try wrapping the code in try / except.

RichieHindle
Wow... :-( I feel 10x stupid. Not a good first post to stackoverflow...I forgot to import re. I was using cgitb and I thought it threw an error when I forgot to import something. Thanks so much.
RogueFalcon
@RogueFalcon: Welcome to SO! We all hope you enjoy your time here. There is absolutely no use in feeling stupid. Think of it this way: you'll probably never make this mistake again :)
Adam Bernier
I almost got it, but your answer was more insightful :))
Armandas
@Armandas: true...
RogueFalcon