def change():
level1 = ""
level2 = ""
file_name = fd.askopenfilename()
file_name1 = 'Новый файл'
f = open(file_name,'r')
lines = f.read()
lines = lines.replace(';--------------', '')
lines = lines.replace('Путей в парке:', '')
while " " in lines:
lines = lines.replace(" ", " ")
save_changes = open(file_name1,'w')
for line in lines.split('\n'):
result1 = re.match('^@\s+(\d+)\s+(.*)$', line)
if result1:
level1 = f'{result1.group(1)};{result1.group(2)}'
continue
if re.match('#', line):
level2 = line
level2 = level2.replace('#', '')
level2 = level2.replace(' ', ';')
continue
if level1 and level2:
line = line.replace(' ', ';')
print(f'{level1};{level2};{line}')
save_changes.write("{}{}{}{}".format(level1, level2, line, "\n"))
save_changes.close()