У меня проблема с программой отслеживания времени, когда я пытаюсь идентифицировать строку в файле, перебирая ее, а затем записывая строки, ЕСЛИ в ней нет чего-либо с переменной «удалить», по какой-то причине она проходит через файл и сказать, что он удален, но цикл не удаляет строки.
date = input(" What is today's date? month-day-year format please. (E.G. 01-14-2003) ")
if os.path.exists(date):
today = open(date, "r")
print(today.read())
delete = input(" Which appointment would you like to delete? (Please type the time E.G. 7:00) ")
#Open the file, save the read to a variable, iterate over the file, check to see if the time is what user entered, if it is not then write it to the line, close the file.
fileEdit = open(date, "r+")
for line in today.readline():
print(line)
if delete not in line:
fileEdit.write(line)
print(fileEdit.read())
today.close()
fileEdit.close()
print ("Appointment deleted, goodbye")
if delete not in line:
когда-нибудьFalse
? Попробуйте это, вставив:else: print 'Deleting line.'
. Также открывайте такие файлы:with open('filename.txt', 'w') as f:
. - person Aleksander Lidtke   schedule 07.11.2013