0
所以我有这个Python代码我正在打开一个文件,并从中读取最大和最小分数百分比,然后显示最大分数的团队以及具有分得分是0.75和0.125 我不断收到此错误信息:Python从文件中读取
ValueError: invalid literal for int() with base 10: '0.75'
我会很感激的任何帮助,请和谢谢。
这是我与http://www.filedropper.com/nfldata
工作文件下面是我的代码:
def create_score_list(nfl_file):
"""Create a list of teams and scores from nfl_file."""
# 2a create a score list and initialize it to empty
score_list = []
for line in nfl_file: # 2b. get each line from the file
if line[0:28] == 'National Football Conference' or\
'NFC EAST' in line or\
'NFC NORTH' in line or\
'NFC SOUTH' in line or\
'NFC WEST' in line or\
'AFC EAST' in line or\
'AFC NORTH' in line or\
'AFC SOUTH' in line or\
'AFC WEST' in line:
continue # skip header line
line_list = line.split(',') # 2bI. csv => split on comma
# create tuple:
team_tuple = (int(line_list[4]), line_list[0])
score_list.append(team_tuple) # 2bII. append tuple
return score_list
耶字符串问题是我面临什么,但我得到了什么你没有感谢您的帮助真的很感激! – Manny
我很高兴这为你工作。如果此答案对您有帮助,请点击复选标记,考虑[接受](http://meta.stackexchange.com/q/5234/179419)。 :) –