-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclass_fill_the_new_lines.py
More file actions
42 lines (34 loc) · 1.2 KB
/
Copy pathclass_fill_the_new_lines.py
File metadata and controls
42 lines (34 loc) · 1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
"""
This script solves the problem that when copy-pasting from pdf files, texts come in
line by line as new lines. Makes text copied from pdf to be on a single line.
Created by AKE - 19.04.22
"""
class FillTheNewLines:
"""
This class solves the problem that when copy-pasting from pdf files, texts come in
line by line as new lines. Makes text copied from pdf to be on a single line.
"""
def __init__(self, file_name):
self.file_name = file_name
def main(self):
"""
Reads the file of raw text and returns the text.
"""
with open(self.file_name, "r", encoding="UTF-8") as file:
text = file.read()
return self.delete_new_lines(text)
def delete_new_lines(self, text):
"""
Deletes all new lines from the raw text.
"""
text = text.replace("\n", " ")
return self.write_to_file(text, "output.txt")
@classmethod
def write_to_file(cls, text, output_file_name):
"""
Writes the revised text to the output file.
"""
with open(output_file_name, "w", encoding="UTF-8") as file:
file.write(text)
return text
# FillTheNewLines("text.txt").main()