The problem to solve is this:
I got some data like this in a text file
|
1
2
3
|
0001___data___are___important
0002___data___are___important
0003___data___are___important
|
I want the data to be like this
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
0001
data
are
important
0002
data
are
important
0003
data
are
important
|
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 templatesTwitter: @pythonprogrammi - python_pygame
Claude's Games
1. Memory gameVideos
Speech recognition gamePygame's Platform Game