views:

1083

answers:

6

Hi

I keep getting invalid syntax with the below:

if (row[0] == year) and (row[1] == month) and (row[2] == day and (row[3] == hour) and (row[4] == minute):
       print "hello"
      else:
       print "hello2"

Any ideas?

+11  A: 

A closing paren is missing at row[2] == day.

angus
+9  A: 

You're missing a closing parenthesis:

if (row[0] == year) and (row[1] == month) and (row[2] == day and (row[3] == hour) and (row[4] == minute):
                                                           ^^^

Also, beware indentation.

Konrad Rudolph
+1 for indentation. The missing paren is not the only error.
balpha
A: 

Try:

if row[0:5] == [year, month, day, hour, minute]:

That fixes your error and makes the whole thing much more readable.

Aaron Digulla
except that list is not equal to tuple
SilentGhost
and number of elements differs
SilentGhost
Ooops. Fixed. But it's still more reable and easy to fix :)
Aaron Digulla
+13  A: 

If "row" is a list, you can do this instead (for clarity):

if row[:5] == [year, month, day, hour, minute]:

..or if row is a tuple:

if row[:5] == (year, month, day, hour, minute):
truppo
A: 

Add a colon after "hour)" along with the aforementioned ")"

Hey BigDaddy, try using the horizontal scroll bar :-)
John Machin
A: 

You have 5 superfluous left parentheses but only 4 superfluous right parentheses. Consider losing ALL the parentheses!

John Machin