반응형
저는 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']
인쇄 된 출력을 텍스트 파일에 저장하려면 어떻게합니까?
해결 방법
모든 답을 요약하고 더 추가하겠습니다.
참조 페이지 https://stackoverflow.com/questions/25023233
반응형
'파이썬' 카테고리의 다른 글
파이썬 Python 인터프리터에 코드 복사 및 붙여 넣기 (0) | 2020.12.12 |
---|---|
파이썬 scikit-learn의 Imputer 모듈로 결 측값 예측 (0) | 2020.12.12 |
파이썬 Python Regex-일치 항목의 위치와 값을 얻는 방법 (0) | 2020.12.12 |
파이썬 플라스크 값 오류보기 기능이 응답을 반환하지 않았습니다. (0) | 2020.12.12 |
파이썬에서 배열을 선언하고 채우는 방법은 무엇입니까? (0) | 2020.12.12 |
댓글