我是新來的python,所以這是我的問題。 我在第一行if之後的第31行 - > y_list中收到錯誤「IndentationError:expected an indendum block」。 我加載的文件包含了很多數字,並且想法是跳過所謂的y_list中的負數。Python - IndentationError:預計在一個縮進塊如果
filename = "data_5.dat" # this file can also be found in the sandbox folder
x_list = []
y_list = []
fp = open(filename)
for line in fp:
var1, var2 = line.split(",") # here we wish to split the line using the ',' character
# since we want them in numeric format we need to convert
a = float(var1)
b = float(var2)
# put them into two lists
x_list.append(a)
y_list.append(b)
fp.close() # close the file
x = x_list
y = y_list
I = 0.0
L = 0.0
for k in range(1, len(x)):
if y_list>0:
y_list.append(y)
I += y[k-1] * (x[k] - x[k-1])
for k in range(1, len(x)):
if y_list>0:
y_list.append(y)
L += y[k] * (x[k] - x[k-1])
print I
print L
print (I+L)/2
這兩個'如果y_list> 0:'行應縮進四個空格。 – eumiro 2013-03-19 13:05:40
@eumiro,這可能是標記系統的人工產物。在純文本中,這些行是縮進的,但使用製表符而不是空格。 – Kevin 2013-03-19 13:06:19
@Kevin:這是一個很大的提示*至於這裏有什麼不對.. – 2013-03-19 13:16:37