from tkinter import filedialog from tkinter import * root = Tk() root.filename = filedialog.askopenfilename(initialdir = "/",title = "Select file",filetypes = (('text files', '.txt'),("all files","*.*"))) print (root.filename) print("modification du CODE 4 et CODE 5\nrepetition du code 2499 en 2493") fp = open(root.filename, "r") f2 = open(root.filename+ "code 99 modif.txt", "w") repeat=None for ligne in fp: print(ligne) if "2499" in ligne: repeat=ligne continue # if if "2498" in ligne: repeat=None continue # if if repeat is not None: print(repeat.replace("+0000000000000004 42....+0000000000000000 43....+0000000000000000 44....+0000000000000000", "+0000000000001103 42....+0000000000000000 43....+0000000000000000 44....+0000000000000000\n*410004+0000000000001503 42....+0000000000000000 43....+0000000000000000 44....+0000000000000000\n*410004+0000000000002453 42....+0000000000000000 43....+0000000000000000 44....+0000000000000000")\ .replace("+0000000000000005 42....+0000000000000000 43....+0000000000000000 44....+0000000000000000", "+0000000000001113 42....+0000000000000000 43....+0000000000000000 44....+0000000000000000\n*410004+0000000000001513 42....+0000000000000000 43....+0000000000000000 44....+0000000000000000\n*410004+0000000000002463 42....+0000000000000000 43....+0000000000000000 44....+0000000000000000")\ .replace("+0000000000002499 42....+0000000000000000 43....+0000000000000000 44....+0000000000000000", "+0000000000002493 42....+0000000000000000 43....+0000000000000000 44....+0000000000000000")\ .replace("+0000000000002498 42....+0000000000000000 43....+0000000000000000 44....+0000000000000000", "+0000000000002493 42....+0000000000000000 43....+0000000000000000 44....+0000000000000000")) # for #f2.write(repeat) #f2.write() """print(repeat.replace("+0000000000000004 42....+0000000000000000 43....+0000000000000000 44....+0000000000000000", "+0000000000001103 42....+0000000000000000 43....+0000000000000000 44....+0000000000000000\n*410004+0000000000001503 42....+0000000000000000 43....+0000000000000000 44....+0000000000000000\n*410004+0000000000002453 42....+0000000000000000 43....+0000000000000000 44....+0000000000000000")\ .replace("+0000000000000005 42....+0000000000000000 43....+0000000000000000 44....+0000000000000000", "+0000000000001113 42....+0000000000000000 43....+0000000000000000 44....+0000000000000000\n*410004+0000000000001513 42....+0000000000000000 43....+0000000000000000 44....+0000000000000000\n*410004+0000000000002463 42....+0000000000000000 43....+0000000000000000 44....+0000000000000000")\ .replace("+0000000000002499 42....+0000000000000000 43....+0000000000000000 44....+0000000000000000", "+0000000000002493 42....+0000000000000000 43....+0000000000000000 44....+0000000000000000")\ .replace("+0000000000002498 42....+0000000000000000 43....+0000000000000000 44....+0000000000000000", "+0000000000002493 42....+0000000000000000 43....+0000000000000000 44....+0000000000000000")) #on ecrit tout dans le fichier f2 = open(root.filename+ "code4 modif 99.txt", "a") #ajout a la fin du fichier un text f2.write("\n*410004+0000000000000126 42....+0attention ligne 43....+parralele pour00 44....+00les trottoires\n") """ # with fp.close() f2.close()