A file sports.dat contains information in following formal Event Participant. Write a function that would read contents from file sports.dat and creates a file named Athletics. dat copying only those records from sports.dat where the event name is “Athletics”
Answer:
def
athletic
():
f1=open(
"sports.dat"
,
'r'
)
f2=open(
"Athletics.dat"
,
'w'
)
l=f1.readlines()
for
line
in
l:
if
line.startswith(
"Athletics"
):
f2.write(line)
f2.write(
"\n"
)
f1.close()
f2.close()
File sports.dat:
File Athletics.dat: