I need to move these three lists of data to a tab-delimited text file. I only know how to print them consecutively (as I have done below).
import requests
import datetime as dt
import xmltodict
url='http://forecast.weather.gov/MapClick.php?lat=47.6062&lon=-122.3321&FcstType=digitalDWML'
r = requests.get(url)
with open('KBFI_2.txt','wb') as outfile:
result = xmltodict.parse(r.text)
pop = result['dwml']['data']['parameters']['probability-of-precipitation']['value']
pop = '\n'.join(pop)
hqpf = result['dwml']['data']['parameters']['hourly-qpf']['value']
hqpf = '\n'.join(hqpf)
d = result['dwml']['data']['time-layout']['start-valid-time']
for dte in d:
date = dt.datetime.strptime(dte.rsplit("-",1)[0],"%Y-%m-%dT%H:%M:%S")
print >>outfile, date
print >>outfile, pop
print >>outfile, hqpf
outfile.close()
I'm sure this is a really easy fix, but I'm a newbie so I'm lost. All help is appreciated!
outfile.close(), as that is handled automatically by thewithstatement.