A certainl part of an if() structure never gets executed.

Νικόλαος Κούρας support at superhost.gr
Wed Jun 12 13:13:21 EDT 2013


On 12/6/2013 7:40 μμ, MRAB wrote:
> On 12/06/2013 12:17, Νικόλαος Κούρας wrote:
>>
>>> As with most of your problems you are barking up the wrong tree.
>>> Why not use the actual value you get from the form to check whether you
>>> have a valid month?
>>> Do you understand why "0" is submitted instead of "=========="?
>>>
>>> Bye, Andreas
>>
>> I have corrected the enumerate loop but it seems thet now the year works
>> and the selected name nad month fail:
>>
>>         if '=' not in ( name and month and year ):
>>             cur.execute( '''SELECT * FROM works WHERE clientsID =
>> (SELECT id FROM
>> clients WHERE name = %s) and MONTH(lastvisit) = %s and YEAR(lastvisit) =
>> %s ORDER BY lastvisit ASC''', (name, month, year) )
>>         elif '=' not in ( month and year ):
>>             cur.execute( '''SELECT * FROM works WHERE MONTH(lastvisit)
>> = %s and
>> YEAR(lastvisit) = %s ORDER BY lastvisit ASC''', (month, year) )
>>         elif '=' not in year:
>>             cur.execute( '''SELECT * FROM works WHERE YEAR(lastvisit)
>> = %s ORDER
>> BY lastvisit ASC''', year )
>>         else:
>>             print( '<h2><font color=red>Πώς να γίνει αναζήτηση αφού
>> δεν επέλεξες
>> ούτε πελάτη ούτε μήνα ή τουλάχιστον το έτος?' )
>>             print( '<meta http-equiv="REFRESH"
>> content="5;/cgi-bin/pelatologio.py">' )
>>             sys.exit(0)
>>
>>
>> i tried in , not in and all possible combinations. but somehow it
>> confuses me.
>>
>> doesn't that mean?
>>
>>         if '=' not in ( name and month and year ):
>>
>> if '=' does not exists as a char inside the name and month and year
>> variables?
>>
>> i think it does, but why it fails then?
>>
> You think it does, but you're wrong.

How would you telll in english word what this is doing?

if '=' not in ( name and month and year ):


and then what this is doing?

if '=' not in ( name or month or year ):

Never before i used not in with soe many variables in parenthesi, up 
until now i was specified it as not in var 1 and not in var 2 and not in 
var 2 and so on....




More information about the Python-list mailing list