【发布时间】:2013-12-25 02:35:42
【问题描述】:
我正在尝试编写一个程序来对文件中的行进行排序和标记。例如,假设我有一个健康诊所的 .txt 文件,其中包含有关患者的各种信息。我想标记信息。假设数据按以下顺序给出:
Patient ID
Age
Gender
Height
Weight
HBA1C level
Cholesterol
Smoker status
Systolic BP
Diastolic BP
并假设该文件包含以下信息(都是编出来的):
A31415
54
M
180
90
6.7
100
No
130
65
A32545
62
F
160
80
7.2
120
Yes
180
92
我的问题是尝试为每个患者编写一个循环,用
A31415
54
M
180
90
6.7
100
No
130
65
成为一名患者并且
A32545
62
F
160
80
7.2
120
Yes
180
92
是第二个。我正在努力让代码产生以下结果:
<patient>
<patientID> A31415 </patientID>
<clinic> UIHC </clinic>
<age> 54 </age>
<gender> M </gender>
<height> 180 </height>
<weight> 90 </weight>
<hba1c> 6.7 </hba1c>
<cholesterol> 100 </cholesterol>
<smoker> No <smoker>
<systolic> 130 </systolic>
<diastolic> 65 </diastolic>
</patient>
<patient>
<patientID> A32545 </patientID>
<clinic> UIHC </clinic>
<age> 62 </age>
<gender> F </gender>
<height> 160 </height>
<weight> 80 </weight>
<hba1c> 7.2 </hba1c>
<cholesterol> 120 </cholesterol>
<smoker> Yes </smoker>
<systolic> 180 </systolic>
<diastolic> 92 </diastolic>
</patient>
任何帮助将不胜感激。
【问题讨论】:
-
请向我们展示您已经尝试过的代码。
标签: python python-3.x