Skip to content Skip to sidebar Skip to footer

Python Elif: Syntax Error

Hi guys I have a syntax error that I really don't understand... Anyone can help? I get this message on the console: File './data_4.0.1.py', line 170 elif: ^ SyntaxError: in

Solution 1:

you end the if block in the previous line when put a instruction at the same level indentation that the if statement

if condition:stuffsomething# doing this close the if block

and a elif can only happen in a if block

and you do that in

if row_count == 0:
        for i in new_list:
            da_appendere = i
            reportwriter.writerow(da_appendere)
    csvfile.close() #<-- here you close the if block#controllo ultimo timestamp    elif:    #<-- you forgot the condition, and is outside of a 'if' block withopen(nomen, 'rb') as f:
            last_timestamp = f.readlines()[-1].split(",")[0]

futhermore you forget to put a condition in the elif, if you don't need one use else instead

Solution 2:

If you do not have another if statement, you should use else instead of elif. See the documentation regarding control-flow.

Post a Comment for "Python Elif: Syntax Error"