我是Python的新手.我需要从dict查询项目并将结果保存到文本文件中.这就是我所拥有的:
import json
import exec.fullog as e
input = e.getdata() #input now is a dict() which has items, keys and values.
#Query
print 'Data collected on:', input['header']['timestamp'].date()
print '\n CLASS 1 INFO\n'
for item in input['Demographics']:
if item['name'] in ['Carly', 'Jane']:
print item['name'], 'Height:', item['ht'], 'Age:', item['years']
for item in input['Activity']:
if item['name'] in ['Cycle', 'Run', 'Swim']:
print item['name'], 'Athlete:', item['athl_name'], 'Age:', item['years']
如何将打印输出保存到文本文件?