Aug-08-2018, 02:49 PM
Hi, how can I go a line starting with a precise word ? After my first condition, I need to go to the line starting with "/22/" (I have to browse my file in different directions) and add new_name to the new_line, but the result of my first condition isn't persisted through the code...
for fichier in os.listdir("result/"): if not fnmatch.fnmatch(fichier, 'file_0.txt'): with fileinput.input(["result/"+fichier], inplace=1) as file_X : # file_X.write('\r\ncoucou') print("---------------------------------") for line in file_X: line = line.strip('\n') if line.startswith("/54/"): split = line.split("/") num = split[2] # print(num) for pj in pjCSV: if num in pj: ... new_name = "jacques" sys.stderr.write(new_name + "\r\n") if line.startswith('/22/'): new_line = line + new_name # new_name is not detected print(line.replace(line, new_line)) continue print (line.rstrip('\n')) # ecriture de toutes les lignes break