# coding:utf-8import time # the time formatting and operation of the backup file is paused using import shutil # as a file backup using # requirements description "" # Requirements: # 1, can enter the document path name;# 2, text wrap input, # 3, text Auto-save, # 4, readable text # 5, overwriting overrides, # 6, overwriting overrides, backing up the previous file. "" "# definition read document function Def read_text (text_url): with open (text_url, " R ") as read: for i in read.readlines (): print i print "*" * 20, "End of document content display", "*" * 20# definition of continued write document function def continue_write (text_url): write_flag = 1 read_ Flag = 1 while write_flag == 1: print "Please enter what you need to enter: \ n" get_new_string = raw_input () with open (text_url, "A +") as write: write.write ("\ n" + get_new_string) # one line break for each input while read_flag == 1: print "The value you entered is saved and you choose whether to print the view?" \ n " print " any key, it means view! \ n Enter Q or Q do not view, continue to enter! \ n " get_search_input_key = Raw_input () if get_search_input_ key == "Q" or get_search_input_key == "Q": continue_write (Text_url) read_flag = 0 else: Read_text (Text_url) read_flag = 0 print "If you are sure you want to quit editing, please enter Q or Q to exit!" \ n " " any key, it means accept continue input! \ n " get_input_key = raw_input () if get_input_key == "Q" or get_input_key == " Q ": print "GoodBye ..." write_flag = 0 else: read_flag = 1 # can again determine if a read operation is required continue # continue circular write operation # definition rewrite document function def cover_write (text_url): flag_write = 1 print "Backing up the original files, backup files with system time and. Bak as backup files!" \ n " # reference time module to format the system times # shutil.copy The first parameter is the original file path, The second parameter is the backup file path shutil.copy (text_url, text_url + ".") + time.strftime ("%y%m%d%h%m%s") + ". Bak") print "Please wait 2 seconds, Backup time as original file ... \ n " time.sleep (2)   &Nbsp; print "Now you can rewrite your files ... \ n" print "Please enter what you want to rewrite ... \ n" get_input_string = raw_input () with open (text_url, "W") As cover: cover.write (get_input_string) while flag_write == 1: print " Would you like to continue typing? \ n " " any key continues to enter, Enter Q or Q to exit the input! " get_write_continue_key = raw_input () if get_write_continue_key == "Q" or get_write_ continue_key == "Q": flag_ write = 0 else: continue_write (Text_url) flag_write = 0 print "Your current document content is: \ n" read_ Text (TEXT_URL) # System Main program entry if __name__ == "__main__": print r " Please enter the path and name of the document you want to read. " print r" Example: E:\Users\Administrator\Desktop\test.txt " print "Please enter: \ n" text_url = raw_input () print "\ n" print "*" * 20, "Document content display Start", "*" * 20 # Call View Document function read_text (text_url) # The space is printed to separate the contents of the document print ' \ n ' # print 50 *, also for delimiter use print '-*-' * 10, "Go to Main program", "-*-" * 10 print "Do I need to continue adding new content? \ n " " any key means continue input \ n " "Enter quit, then quit!" \ n " " input cover, then overwrite the full text again! The system will automatically back up old documents, please do it carefully! " is_continue_or_cover = raw_input () if is_ continue_or_cover == "Quit": print "GoodBye ..." elif is_continue_or_cover == "Cover": cover_write (Text_url) else: continue_write (text_url )
This article is from the "as1024" blog, make sure to keep this source http://as1024.blog.51cto.com/12241298/1954814
Python implements read, resume, overwrite override automatic backup of operation document