elif语句的语法无效

时间:2016-03-15 12:09:57

标签: csv python-3.x

我无法看到这里的无效语法是什么,任何帮助都将不胜感激。

if alpha == "alpha":
    updatefile('Class 1 Results.csv',0,"1")

    elif Class == "2":    
        with open('Class 2 Results.csv', 'a') as f:
            file_writer = csv.writer(f, delimiter=',',lineterminator='\n')
            file_writer.writerow((name, score))sortcsv('Class 2 Results.csv', 0) 

1 个答案:

答案 0 :(得分:3)

试试这个:

if alpha == "alpha":
    updatefile('Class 1 Results.csv',0,"1")
elif Class == "2":
    with open('Class 2 Results.csv', 'a') as f:
        file_writer = csv.writer(f, delimiter=',',lineterminator='\n')
        file_writer.writerow((name, score))sortcsv('Class 2 Results.csv', 0)

正如@ poke的评论中提到的,空格在Python中很重要。这就是为什么缩进必须正确的原因 - 例如,在if声明中,ifelifelse都必须在相同级别的缩进。