Convert some data into another format

The problem to solve is this:

I got some data like this in a text file

 

I want the data to be like this

 

import tkinter as tk
from tkinter import filedialog
import os


root = tk.Tk()
root.withdraw()

my_filetypes = [('text files', '.linee'), ('all files', '.*')]
answer = filedialog.askopenfilename(parent=root,
                                    initialdir=os.getcwd(),
                                    title="Please select a file:",
                                    filetypes=my_filetypes)


with open(answer, "r", encoding="utf-8") as file:
    file = file.read()
print(file)


text = file.replace("\n", "\n\n")

text = text.replace("___", "\n")


with open(answer[:-6] + ".txt", "w", encoding="utf-8") as file:
    file.write(text)

textfile = answer[:-6] + ".txt"
os.startfile(textfile)

root.mainloop()

 


Subscribe to the newsletter for updates
Tkinter templates
My youtube channel

Twitter: @pythonprogrammi - python_pygame

Videos

Speech recognition game

Pygame's Platform Game

Other Pygame's posts