mystr="here\n is\n my\n string\n"
print(mystr)
, here\n is\n my\n string\n
print(mystr, file=(open('myfile.txt', 'w', newline='\n')), sep='\\n')
то в файле тоже просто here\n is\n my\n string\n
here
is
my
string
mystr="here\n is\n my\n string\n"
with open('myfile.txt', 'w') as f:
f.write(mystr)
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)
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))