Hi there. For some reason I am struggling with this problem. The purpose of this
problem is to take an existing .py file and change it so instead of writing to
a screen, it has to be written to an output file. The output file will be a csv
file.
I know how write to an output file, it creates the csv file but doesn't print
anything there yet. The problem is that says ,"outfile is not defined"
I cannot figure out why! Is there something else I need to define? or something is wrong?
In line 13 is the outfile where it says it's not defined. I have outfile on the top.
Any help would be appreciated...
def makeMagnitudeList():
quakefile = open("earthquakes.txt","r")
outfile = open("extractMag.csv","w")
headers = quakefile.readline()
maglist = [ ]
for aline in quakefile:
vlist = aline.split()
maglist.append(float(vlist[1]))
return maglist
magList = makeMagnitudeList()
outfile.write(makeMagnitudeList())
print(magList)