On Tue, 11 Jun 2013 13:20:52 -0700, Νικόλαος Κούρας wrote: > The above if structure works correctly *only* if the user sumbits by > form: > > name, month, year or month, year > > If, he just enter a year in the form and sumbit then, i get no error, > but no results displayed back. > > Any ideas as to why this might happen?
Yes, I know exactly why this is happening. It is for one of two reasons. You may determine which one using the following secret code which I stole from the illuminati in 1836: import random reason = { 1: "Input data is not as expected by coder", 2: "Flow control logic not performing as coder expects", 3: "Badger Badger Badger Badger Badger Badger Badger Badger Mushroom", 4: "Please try again", 5: "Snaaaaake", 6: "Grumpy cat says fix your own damn code", 7: "I'll be back" } print reason[ random.choice( reason.keys() ) ] Note - this only has a small chance of actually doing what you want (ie giving a possibly accurate answer), but it sounds as if that's a level of precision you're used to working with anyway. On a slightly more serious note, if you can't apply yourself to debugging a case of "the program logic isn't doing what I expect" for some value of program logic that you coded, that may be a hint that: a) you don't actually understand what the program logic is doing b) you shouldn't be writing logic so complex that you can't see how to debug it c) your logic is overly convoluted and complex d) all of the above So perhaps you need to scrub the logic altogether, and start again taking smaller steps. You could also perhaps do with a lesson in De Morgan's theorem: not a and not b and not c = not ( a or b or c ) not a or not b or not c = not ( a and b and c ) and sometimes the alternative form is easier to understand Now, looking at your code here are two important questions: (1) What is the initial values of name, month and year? (2) Which block is actually being executed? Bear in mind that if a branch other than one you expect to be executed is executing, the fail condition might not be what you think it is. Specifically, is it possible that the code is executing the wrong branch and tripping up when it tries to generate or perhaps execute the sql statement empty strings, or just not getting any result from the sql because of the empty strings? Hint - take the code from the current file, apply a liberal smattering of print statements, and test it for various values of month, year and name. def test(name, month, year): print "name, month, year ::", name, month, year if not re.search( '=', name ) and not re.search( '=', month ) and not re.search( '=', year ): print "branch 1" elif not re.search( '=', month ) and not re.search( '=', year ): print "branch 2" elif not re.search( '=', year ): print "branch 3" else: print "branch 4" # testing logic for 8 possible input conditions test("=", "=", "=") test("=", "=", "x") test("=", "x", "=") test("=", "x", "x") test("x", "=", "=") test("x", "=", "x") test("x", "x", "=") test("x", "x", "x") -- Denis McMahon, denismfmcma...@gmail.com -- http://mail.python.org/mailman/listinfo/python-list