0
我需要扫描我的.csv文件中的每一行,但一旦我到达最后,它会给我一个错误。需要帮助扫描通过.csv文件的线条
def percentage():
for line in csv_file:
temp = line.strip("\n")
measureType = temp.split(",")[5][1: -1]
if measureType == "PERCENT":
year = line.split(",")[1][1: -1]
percentage = line.split(",")[6][1: -2]
country = line.split(",")[0][1: -1]
if float(percentage) < 50:
output.addCountry(country, year, percentage)
当我通过文件扫描,一旦它到达终点,它给了我一个错误:
IndexError: list index out of range
下面一行:
measureType = temp.split(",")[5][1: -1]
我感到非常困惑并不知道我必须解决什么问题。
文件的最后一行是什么? – cosinepenguin
听起来这个文件最后有一个空行。 – tdelaney