On 06/11/2013 02:20 PM, Νικόλαος Κούρας wrote:
> [code]
>               if not re.search( '=', name ) and not re.search( '=', month ) 
> and not re.search( '=', year ):

What do each of these functions return?  When you print out
re.search('=', name) what happens?

When you're debugging you should print each of these out.  Also make a
standalone program (NOT A CGI SCRIPT) for debugging.  You can test
various inputs by simply going:

name = "My test name"
month = "Thirteenth"
year = "2013"

One thing I do is to make my code into functions and then at the bottom
of each script I have something like this:

if __name__ == "__main__":
    # run some test code here
    # or alternatively do the CGI stuff depending on what
    # mode you're in.

You could even put in debugging flags (apologies to Rick who recently
raved against needing to resort to this sort of thing).

Consider this code:
---------- do_something.py -----------------------
debug = False

def do_something(name, month, year):
    if debug:
        print re.re.search( '=', name )
        print not re.search( '=', month )
        print not re.search( '=', year )
    if not re.search( '=', name ) and not re.search( '=', month ) and
not re.search( '=', year ):
        print "gonna do query"
        # code follows

if __name__ == "__main__"
    debug = True
    do_something("bob", None, 2012)
    do_something(None, None, None)
    do_something("big", "Octember", 2067)
    # other use cases here

-------------------------------------------------

Then in your cgi script itself, you just do this:
----------- my_cgi_script.py -------------------
import do_something

# handle cgi stuff
# get name, month year
dosomething.dosomething(name, month, year)
------------------------------------------------
Now to test your code you can just run the module directly with python,
and once you've got it working, the CGI will also work, since it pulls
in the same code.

If this concept is new to you, I strongly urge you to stop development
and read through a good python tutorial or get a good python book.
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to