IndentationError:期望缩进的数据集= list()

时间:2018-08-05 14:08:29

标签: python linear-regression

在运行下面的第二个代码时遇到此错误。有人可以告诉我如何解决它吗?

File "<ipython-input-2-b17fa66ce8c6>", line 3
    dataset = list()
          ^
IndentationError: expected an indented block


def load_csv(filename):
dataset = list()
with open(filename, 'r') as file:
csv_reader = reader(file)
for row in csv_reader:
if not row:
continue
dataset.append(row)
return dataset

1 个答案:

答案 0 :(得分:1)

标签和空格在Python中非常重要。您的代码应如下所示:

def load_csv(filename):
    dataset = list()
    with open(filename, 'r') as file:
        csv_reader = reader(file)
        for row in csv_reader:
            if not row:
                continue
            dataset.append(row)
    return dataset