获取“错误”除非 - python
我得到了一种错误messagge,我不应该使用“裸露的...” 我必须检查第三个charachter是一个点('。')的“文本文件的行”(保存在RAW_RESULTS ...)中。 有其他方法避免使用尝试...除外吗?
THX寻求帮助
with open(file_to_read, 'r') as fi:
raw_results = fi.readlines()
date_of_game = []
home_team = []
away_team = []
home_team_goals = []
away_team_goals = []
for i in range(len(raw_results)):
try:
if raw_results[i][2] == '.':
date_of_game.append(raw_results[i][:5])
if raw_results[i + 1] != "A Tav.":
home_team.append(raw_results[i + 1].strip('\n'))
away_team.append(raw_results[i + 2].strip('\n'))
home_team_goals.append(raw_results[i + 3].strip('\n'))
away_team_goals.append(raw_results[i + 4].strip('\n'))
else:
home_team.append(raw_results[i + 2].strip('\n'))
away_team.append(raw_results[i + 3].strip('\n'))
home_team_goals.append(raw_results[i + 4].strip('\n'))
away_team_goals.append(raw_results[i + 5].strip('\n'))
except:
''' ... do nothing '''
I get a sort of Error Messagge that I should not use a "bare Except ..."
I have to check the 'line of the text file' (saved in raw_results ...) in which the third charachter is a dot ('.').
Is there another way avoiding to use Try ... Except ?
Thx for help
with open(file_to_read, 'r') as fi:
raw_results = fi.readlines()
date_of_game = []
home_team = []
away_team = []
home_team_goals = []
away_team_goals = []
for i in range(len(raw_results)):
try:
if raw_results[i][2] == '.':
date_of_game.append(raw_results[i][:5])
if raw_results[i + 1] != "A Tav.":
home_team.append(raw_results[i + 1].strip('\n'))
away_team.append(raw_results[i + 2].strip('\n'))
home_team_goals.append(raw_results[i + 3].strip('\n'))
away_team_goals.append(raw_results[i + 4].strip('\n'))
else:
home_team.append(raw_results[i + 2].strip('\n'))
away_team.append(raw_results[i + 3].strip('\n'))
home_team_goals.append(raw_results[i + 4].strip('\n'))
away_team_goals.append(raw_results[i + 5].strip('\n'))
except:
''' ... do nothing '''
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
解决裸露的异常错误:
您可以添加
以继续循环
to solve the bare exception error:
you can add
to continue it's looping