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}')
final_line = "{}{}{}{}".format(level1, level2, line, "\n")
if final_line.count(';') >= 6:
save_changes.write(final_line)
save_changes.close()
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'):
if line.count(';') < 6:
continue
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()
content = ['CCE\n', ' OpenBabel05262020233D\n', '\n', ' 25 24 0 0 0 0 0 0 0 0999 V2000\n', ' -1.8930 0.1160 -0.0680 N 0 3 0 0 0 0 0 0 0 0 0 0\n', ' -1.2130 -0.7350 0.9170 C 0 0 0 0 0 0 0 0 0 0 0 0\n', ' 0.1910 -1.0760 0.4140 C 0 0 0 0 0 0 0 0 0 0 0 0\n', ' 1.0060 0.1260 0.4020 O 0 0 0 0 0 0 0 0 0 0 0 0\n', ' 2.2870 0.0660 -0.0070 C 0 0 0 0 0 0 0 0 0 0 0 0\n', ' 2.7620 -0.9930 -0.3660 O 0 0 0 0 0 0 0 0 0 0 0 0\n', ' -1.8880 -0.5510 -1.3770 C 0 0 0 0 0 0 0 0 0 0 0 0\n', ' -1.1910 1.4020 -0.1710 C 0 0 0 0 0 0 0 0 0 0 0 0\n', ' -3.2790 0.3470 0.3580 C 0 0 0 0 0 0 0 0 0 0 0 0\n', ' 3.0430 1.1820 -0.0190 N 0 0 0 0 0 0 0 0 0 0 0 0\n', ' -1.1400 -0.2050 1.8670 H 0 0 0 0 0 0 0 0 0 0 0 0\n', ' -1.7820 -1.6540 1.0570 H 0 0 0 0 0 0 0 0 0 0 0 0\n', ' 0.6440 -1.8150 1.0750 H 0 0 0 0 0 0 0 0 0 0 0 0\n', ' 0.1270 -1.4820 -0.5960 H 0 0 0 0 0 0 0 0 0 0 0 0\n', ' -0.8600 -0.7220 -1.6940 H 0 0 0 0 0 0 0 0 0 0 0 0\n', ' -2.4090 -1.5050 -1.3010 H 0 0 0 0 0 0 0 0 0 0 0 0\n', ' -2.3930 0.0810 -2.1080 H 0 0 0 0 0 0 0 0 0 0 0 0\n', ' -1.7870 2.0950 -0.7650 H 0 0 0 0 0 0 0 0 0 0 0 0\n', ' -1.0410 1.8150 0.8260 H 0 0 0 0 0 0 0 0 0 0 0 0\n', ' -0.2240 1.2510 -0.6510 H 0 0 0 0 0 0 0 0 0 0 0 0\n', ' -3.8000 -0.6070 0.4350 H 0 0 0 0 0 0 0 0 0 0 0 0\n', ' -3.2830 0.8420 1.3300 H 0 0 0 0 0 0 0 0 0 0 0 0\n', ' -3.7840 0.9790 -0.3730 H 0 0 0 0 0 0 0 0 0 0 0 0\n', ' 2.6640 2.0280 0.2670 H 0 0 0 0 0 0 0 0 0 0 0 0\n', ' 3.9670 1.1390 -0.3140 H 0 0 0 0 0 0 0 0 0 0 0 0\n', ' 1 2 1 0 0 0 0\n', ' 1 7 1 0 0 0 0\n', ' 1 8 1 0 0 0 0\n', ' 1 9 1 0 0 0 0\n', ' 2 3 1 0 0 0 0\n', ' 2 11 1 0 0 0 0\n', ' 2 12 1 0 0 0 0\n', ' 3 4 1 0 0 0 0\n', ' 3 13 1 0 0 0 0\n', ' 3 14 1 0 0 0 0\n', ' 4 5 1 0 0 0 0\n', ' 5 6 2 0 0 0 0\n', ' 5 10 1 0 0 0 0\n', ' 7 15 1 0 0 0 0\n', ' 7 16 1 0 0 0 0\n', ' 7 17 1 0 0 0 0\n', ' 8 18 1 0 0 0 0\n', ' 8 19 1 0 0 0 0\n', ' 8 20 1 0 0 0 0\n', ' 9 21 1 0 0 0 0\n', ' 9 22 1 0 0 0 0\n', ' 9 23 1 0 0 0 0\n', ' 10 24 1 0 0 0 0\n', ' 10 25 1 0 0 0 0\n', 'M CHG 1 1 1\n', 'M END\n']
with open('myfile.txt', 'w') as f:
f.write(''.join(content))
mystr="CCE\n OpenBabel05262020233D\n \n 25 24 0 0 0 0 0 0 0 0999 V2000\n -1.8930 0.1160 -0.0680 N 0 3 0 0 0 0 0 0 0 0 0 0\n -1.2130 -0.7350 0.9170 C 0 0 0 0 0 0 0 0 0 0 0 0\n 0.1910 -1.0760 0.4140 C 0 0 0 0 0 0 0 0 0 0 0 0\n 1.0060 0.1260 0.4020 O 0 0 0 0 0 0 0 0 0 0 0 0\n 2.2870 0.0660 -0.0070 C 0 0 0 0 0 0 0 0 0 0 0 0\n 2.7620 -0.9930 -0.3660 O 0 0 0 0 0 0 0 0 0 0 0 0\n -1.8880 -0.5510 -1.3770 C 0 0 0 0 0 0 0 0 0 0 0 0\n -1.1910 1.4020 -0.1710 C 0 0 0 0 0 0 0 0 0 0 0 0\n -3.2790 0.3470 0.3580 C 0 0 0 0 0 0 0 0 0 0 0 0\n 3.0430 1.1820 -0.0190 N 0 0 0 0 0 0 0 0 0 0 0 0\n -1.1400 -0.2050 1.8670 H 0 0 0 0 0 0 0 0 0 0 0 0\n -1.7820 -1.6540 1.0570 H 0 0 0 0 0 0 0 0 0 0 0 0\n 0.6440 -1.8150 1.0750 H 0 0 0 0 0 0 0 0 0 0 0 0\n 0.1270 -1.4820 -0.5960 H 0 0 0 0 0 0 0 0 0 0 0 0\n -0.8600 -0.7220 -1.6940 H 0 0 0 0 0 0 0 0 0 0 0 0\n -2.4090 -1.5050 -1.3010 H 0 0 0 0 0 0 0 0 0 0 0 0\n -2.3930 0.0810 -2.1080 H 0 0 0 0 0 0 0 0 0 0 0 0\n -1.7870 2.0950 -0.7650 H 0 0 0 0 0 0 0 0 0 0 0 0\n -1.0410 1.8150 0.8260 H 0 0 0 0 0 0 0 0 0 0 0 0\n -0.2240 1.2510 -0.6510 H 0 0 0 0 0 0 0 0 0 0 0 0\n -3.8000 -0.6070 0.4350 H 0 0 0 0 0 0 0 0 0 0 0 0\n -3.2830 0.8420 1.3300 H 0 0 0 0 0 0 0 0 0 0 0 0\n -3.7840 0.9790 -0.3730 H 0 0 0 0 0 0 0 0 0 0 0 0\n 2.6640 2.0280 0.2670 H 0 0 0 0 0 0 0 0 0 0 0 0\n 3.9670 1.1390 -0.3140 H 0 0 0 0 0 0 0 0 0 0 0 0\n 1 2 1 0 0 0 0\n 1 7 1 0 0 0 0\n 1 8 1 0 0 0 0\n 1 9 1 0 0 0 0\n 2 3 1 0 0 0 0\n 2 11 1 0 0 0 0\n 2 12 1 0 0 0 0\n 3 4 1 0 0 0 0\n 3 13 1 0 0 0 0\n 3 14 1 0 0 0 0\n 4 5 1 0 0 0 0\n 5 6 2 0 0 0 0\n 5 10 1 0 0 0 0\n 7 15 1 0 0 0 0\n 7 16 1 0 0 0 0\n 7 17 1 0 0 0 0\n 8 18 1 0 0 0 0\n 8 19 1 0 0 0 0\n 8 20 1 0 0 0 0\n 9 21 1 0 0 0 0\n 9 22 1 0 0 0 0\n 9 23 1 0 0 0 0\n 10 24 1 0 0 0 0\n 10 25 1 0 0 0 0\n M CHG 1 1 1\n M END\n"
with open('myfile.txt', 'w') as f:
f.write(mystr)
return
x = func1()
y = func2()
z = func3()
func1()
func2()
func3()