Это может быть очень просто, но я до сих пор не могу понять, что такое решение. У меня есть этот код, это образец из более длинного кода.Невозможно записать в текстовый файл из Python
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
и specialistchoose
пришли от входа от пользователя, нажав на радиокнопку и кнопку проверки. Я пытаюсь добавить строковое значение в slotchoose
, doctor
и specialchoose
, а затем сохранить его в текстовый файл. Но проблема в том, что каждый раз, когда я запускаю его, и открываем текстовый файл, test2.txt
, он будет иметь значение specialistchoose
.
Что отладки вы сделали? Пробовали ли вы просматривать значения перед их печатью в файл? Знаете ли вы, что делает режим '' w ''открытых файлов? –