Dec-14-2022, 01:38 PM
lines = texte.split('&')
is wrong, your splitter is &&. & is on begin and end only.
is wrong, your splitter is &&. & is on begin and end only.
in_text = "" out_text = "" # open file, read and split with open("data_groupe_11-12_B.txt", "r") as f: in_text = f.read()[1:-1].split("&&") # for replacements repl = ["title", "year", "duration", "score", "nbvotes", "revenue", "revenue", "restriction", "desc"] # set headers out_text = ";".join(repl).title() out_text += "\n" for line in in_text: line = line.replace(",", ";") for ch in repl: if ch in line: # replacing, (for example title= year= ...) line=line.replace(f"{ch}=", "").replace(" ", "").strip() out_text += f"{line}\n" print(out_text) # save as semicolon seperated text file with open("result.csv", "w") as f: f.write(out_text)