小编Iro*_*ist的帖子

如何将python屏幕输出保存到文本文件

我是Python的新手。我需要从字典查询项目并将结果保存到文本文件。这是我所拥有的:

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']
Run Code Online (Sandbox Code Playgroud)

如何将打印的输出保存到文本文件?

python python-2.7

2
推荐指数
5
解决办法
5万
查看次数

标签 统计

python ×1

python-2.7 ×1