這應該把這個信息放到一個新的文件,但我得到一個錯誤,說'tuple' object has no object 'write'
所以我需要一些幫助來找出我的代碼中有什麼問題。得到這個文件並擺脫錯誤代碼
def codeData(filename):
file = open(filename)
outputFile = ("Project.txt", "w")
#makes file that will take information from given file and write on it
clinic = file.readline().strip() #takes the name of clinic and writes it
patientnumber = int(file.readline().strip()) #takes the amount of patients
for i in range(patientnumber):
outputFile.write("<patient>\n")
outputFile.write("<patientID>"+file.readline().strip()+"</patientID>\n")
outputFile.write("<clinic>"+clinic+"</clinic>\n")
age = int(file.readline().strip())
outputFile.write("<age>"+str(age)+"</age>\n")
outputFile.write("<gender>"+gender+"</gender>\n")
height = int(file.readline().strip())
outputFile.write("<height>"+str(height)+"</height>\n")
weight = int(file.readline().strip())
outputFile.write("<weight>"+str(weight)+"</weight>\n")
hba1 = int(file.readline().strip())
outputFile.write("<hba1>"+str(hba1)+"</hba1>\n")
cholesterol = int(file.readline().strip())
outputFile.write("<cholesterol>"+str(cholesterol)+"</cholesterol>\n")
outputFile.write("<smoker>"+smoker+"</smoker>\n")
systolic = int(file.readline().strip())
outputFile.write("<systolic>"+str(systolic)+"</systolic>\n")
diastolic = int(file.readline().strip())
outputFile.write("<diastolic>"+str(diastolic)+"</diastolic>\n")
file.close()
outputFile.close()
codeData("Project Text.txt")
這裏是什麼是對,它在
UHIC
2
A31415
54
M
180
90
6.7
100
No
130
65
A32545
62
F
160
80
7.2
120
Yes
180
92
好的更新這個問題是,我得到它貫穿一次,它通過列表的第一部分工作,但我需要它再次通過,我不能讓它做到這一點,所以如果有人知道如何解決這個請幫忙? – user3084628