这可能很简单,但我仍然不知道解决办法是什么。我有这个代码,这是一个较长代码的样本。在
radio1Value = slotchoose.get()
if radio1Value == 0:
with open ("test2.txt", "w") as file:
file.write ("Slot : 9 AM - 10 AM")
slot.remove("9 AM")
r12.destroy()
elif radio1Value == 1:
slot.remove("10 AM")
with open ("test2.txt", "w") as file :
file.write ("Slot : 10 AM - 11 AM\n")
r13.destroy()
checkValue = doctor.get()
if checkValue == 1:
with open ("test2.txt", "w") as file :
file.write ("\nDoctor : Dr. Adam Ahmed")
payment = "RM100.00"
elif checkValue == 2:
with open ("test2.txt", "w") as file :
file.write ("Doctor : Dr Adib Kamal")
payment = "RM200.00"
radioValue = specialistchoose.get()
if radioValue == 1 :
with open ("test2.txt", "w") as file :
file.write ("\nSpecialist : Cardiology")
elif radioValue == 2:
with open ("test2.txt", "w") as file :
file.write ("Specialist : Gastroenterology")
elif radioValue == 3:
with open ("test2.txt", "w") as file :
file.write ("Specialist : Dermatology")
elif radioValue == "Psychiatry":
with open ("test2.txt", "w") as file :
file.write("Specialist : Psychiatry")
elif radioValue == "Dentist" :
with open ("test2.txt", "w") as file:
file.write("Specialist : Dentist")
slotchoose
,doctor
,和{slotchoose
、doctor
和specialchoose
添加一个字符串值,然后将其保存到一个文本文件中。但问题是每次我运行它,打开文本文件test2.txt
,它只会有specialistchoose
值。在
{{cd2>你每一次都在重写文件。如果您想累积多次写入文件的文本,则需要使用append模式(
a
)。在Python 2文档:
https://docs.python.org/2/library/functions.html#open
Python 3文档:
https://docs.python.org/3/library/functions.html#open
相关问题 更多 >
编程相关推荐