Reputation: 1379
My code is throwing a SyntaxError: invalid syntax
error at the last else
statement (second to last line in code below). Can anyone see what is causing this? I'm running Python 2.7 on CentOS.
def mintosec(time):
foo = time.split(':')
if re.match('o|O',foo[0]) == True: #check to see if any zeros are incorrectly labled as 'o's and replace if so
div = list(foo[0])
if div[0] == 'o' or 'O':
new = 0
else:
new = div[0]
if div[1] == 'o' or 'O':
new1 = 0
else:
new1 = div[1]
bar = int(str(new)+str(new1))*60
else:
bar = int(foo[0]) * 60
Upvotes: 0
Views: 610
Reputation: 280
another way to test vs more than 1 item is:
if div[1] in {'o', 'O'}:
# stuff.
as described in How do I test one variable against multiple values?
Upvotes: 1
Reputation: 2730
You cannot do:
if div[0] == 'o' or 'O':
new = 0
You must declare it like:
if div[1] == 'o' or div[1] == 'O':
new1 = 0
A better way to do this check would be:
if div[1].lower() == 'o'
Upvotes: 2