delete empty file

This commit is contained in:
Klaudia 2023-04-18 17:38:18 +02:00
parent dbc7207e21
commit 11fb2733e5
5 changed files with 23 additions and 36 deletions

View File

@ -1,27 +1,3 @@
def remove_empty_lines(text):
lines = text.split('\n')
non_empty_lines = []
for line in lines:
if line.strip():
non_empty_lines.append(line)
return '\n'.join(non_empty_lines)
def join_lines(text):
lines = text.split("\n")
joined_lines = [lines[0]]
for line in lines[1:]:
if line.startswith("["):
joined_lines.append(line)
else:
joined_lines[-1] += " " + line
return "\n".join(joined_lines)
def process_text(text, nazwisko_user, nazwisko_system):
lines = text.split('\n')
result=[]
@ -33,19 +9,34 @@ def process_text(text, nazwisko_user, nazwisko_system):
else:
result.append(line)
return '\n'.join(result)
def join_lines(text):
lines = text.split("\n")
joined_lines = [lines[0]]
for line in lines[1:]:
if line.startswith("["):
joined_lines.append(line)
else:
joined_lines[-1] += " " + line
return "\n".join(joined_lines)
def remove_empty_lines(text):
lines = text.split('\n')
non_empty_lines = []
for line in lines:
if line.strip():
non_empty_lines.append(line)
return '\n'.join(non_empty_lines)
def read_tsv(file_path):
with open(file_path, 'r', encoding='utf-8') as tsv_file:
content = tsv_file.read()
return content
def write_tsv(file_path, content):
with open(file_path, 'w', encoding='utf-8') as tsv_file:
tsv_file.write(content)
def replace_first_space_with_tab(text):
lines = text.split("\n")
new_lines = []
@ -57,8 +48,6 @@ def replace_first_space_with_tab(text):
else:
new_lines.append(line)
return "\n".join(new_lines)
if __name__ == '__main__':
# wypelnic przed uruchomieniem
nazwisko_user = ""
@ -66,11 +55,9 @@ if __name__ == '__main__':
numer_user = ""
numer_system = ""
file_path = f"J:\PycharmProjects\systemy_dialogowe\data\dialog-{numer_system}-{numer_user}-01.tsv"
text = read_tsv(file_path )
text = remove_empty_lines(text )
text = join_lines(text )
text = process_text(text, nazwisko_user, nazwisko_system )
text = replace_first_space_with_tab(text )
write_tsv(file_path, text )