def change():
file_name = fd.askopenfilename()
f = open(file_name,'r')
lines = f.read()
lines = lines.replace('Путей в парке', '')
lines = lines.replace(';--------------', '')
while " " in lines:
lines = lines.replace(" ", " ")
level1 = None
level2 = None
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
continue
if level1 and level2:
if level1 and level2 and line:
line = line.replace(' ', '; ')
print(f'{level1};{level2}{line}')
f.close()
save_changes = open(file_name, 'w')
save_changes.writelines(lines)
save_changes.close()
# читаем исходник
text = open('file1.txt', 'r').read()
# изменяем
text += 'test'
# записываем во второй
f = open('file2.txt', 'w')
f.write(text)
f.close()
def change():
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(" ", " ")
level1 = None
level2 = None
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
continue
if level1 and level2:
if level1 and level2 and line:
line = line.replace(' ', '; ')
print(f'{level1};{level2}{line}')
f.close()
save_changes = open(file_name1, 'w')
save_changes.writelines(lines)
save_changes.close()