이번 시즌 모든 프리미어 리그 경기를 파이썬을 사용하여 다운로드 한 JSON 파일을 통해 인쇄하려고합니다. 다음은 내가 사용중인 Json 파일에 대한 링크입니다.- Json 파일
while 루프를 사용하여 첫 번째 매치 데이의 비품을 인쇄했습니다. 데이트, 홈팀, "vs", 어웨이 팀을 원합니다. 다른 매치 데이를 반복하기 위해 외부 루프를 사용해야한다고 생각하지만 도움이 필요합니다.
import json
with open('en.1.json') as json_data:
data = json.load(json_data)
matchday = data['rounds'][0]['matches']
i = 0
while i < len(matchday):
home = matchday[i]['team1']
away = matchday[i]['team2']
date = matchday[i]['date']
print date, home['name'], "vs", away['name']
i = i + 1
다음은 현재 직면하고있는 문제에 대한 간단하고 직관적 인 해결책입니다.
with open(premierleaguedatafile) as data_file:
# loads the entire dataset into a dictionary
data = json.load(data_file)
# get the list of all the rounds of fixtures
rounds = data['rounds']
# iterate over each round
for matchday in rounds:
# store the list of matches played on this matchday
matches = matchday['matches']
# iterate over the matches to get individual match details
for match in matches:
match_date = match['date']
home_team = match['team1']['name']
away_team = match['team2']['name']
print('{} {} vs {}'.format(match_date, home_team, away_team))
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다