如何在python中的for循环中为数组赋值

时间:2015-09-09 10:00:06

标签: python arrays

我对python很新。在尝试使用数组时,我对这部分感到震惊。

这段代码:

with open("top10backup.txt", "r") as filestream:

   count=0

   for line in filestream:

    currentline = line.split("\t")

    print(currentline[0])

    category[count] = currentline[0]

    print(currentline[1])

    source[count] = currentline[1]

    count = count + 1

print (count)

我收到的错误是:

category[count] = currentline[0]

Inconsistent use of tabs and spaces in indentation 

有人可以帮忙解释一下吗?

1 个答案:

答案 0 :(得分:3)

在Python中使用空格来表示不同的代码块,因此当您混合普通空格和制表符时,它会让人感到困惑,因为Python不确定选项卡应该被认为有多少空格。如果找到所有选项卡并将它们转换为空格(确保保留正确的缩进),那么您的代码将运行良好。