Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
append my results to a file
#4
Thank you Larz60+ and Gribouillis for your suggestions. Now the program writes in the original file although it is appending everything to the bottom of the file and I would like to append a number in each file.
About what Gribouillis suggests, the output I get in my screen is:

COC1=C(=C)......
63.95
COC1=CC.....
72.74
C[C@H]1CO...
75.01
CC1CN...
74.57

And want to append in the original file is 63.95 to the first line, 72.72 to the second line and so on, separated from the smiles with a comma, like the first two entries in each file, like this:


Verapamil,sub,COC1=C(OC)C=C(CCN©CCCC(C#N)(C©C)C2=CC(OC)=C(OC)C=C2)C=C1,63.95
Norverapamil,sub,COC1=CC=C(CCNCCCC(C#N)(C©C)C2=CC(OC)=C(OC)C=C2)C=C1OC,72.74
levofloxacin,sub,C[C@H]1COC2=C3N1C=C(C(O)=O)C(=O)C3=CC(F)=C2N1CCN©CC1,75.01


Below I show you what I have now (but it is appending all the orders to the bottom of the file):
Sorry that I can't explain better in English and thank you both very much.

import os
import subprocess
path_input = '/home/c.blanes/pgp/training.txt'
obabel = '/usr/bin/obabel '
 
with open(path_input, 'r') as f_in, open(path_input, 'a') as f_out:

	for line in f_in.readlines():

		smiles = line.split(',')[2].strip('\n')
		print(smiles)
		
		launch = obabel + '-:\'%s\' -otxt --append TPSA'%(smiles)
		
		subprocess.call(launch, shell=True)
		
		f_out.write(launch)
		
Reply


Messages In This Thread
append my results to a file - by clarablanes - Nov-23-2018, 09:40 AM
RE: append my results to a file - by Larz60+ - Nov-23-2018, 10:23 AM
RE: append my results to a file - by Gribouillis - Nov-23-2018, 11:01 AM
RE: append my results to a file - by clarablanes - Nov-23-2018, 03:15 PM
RE: append my results to a file - by Larz60+ - Nov-23-2018, 05:07 PM
RE: append my results to a file - by clarablanes - Nov-23-2018, 06:45 PM
RE: append my results to a file - by Gribouillis - Nov-23-2018, 07:06 PM
RE: append my results to a file - by clarablanes - Nov-23-2018, 09:47 PM
RE: append my results to a file - by Gribouillis - Nov-23-2018, 10:17 PM
RE: append my results to a file - by clarablanes - Nov-23-2018, 10:38 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Updating sharepoint excel file odd results cubangt 1 1,054 Nov-03-2023, 05:13 PM
Last Post: noisefloor
Question How to append integers from file to list? Milan 8 1,694 Mar-11-2023, 10:59 PM
Last Post: DeaD_EyE
  Trying to send file to printer with no results. chob_thomas 2 3,657 Dec-21-2022, 07:12 AM
Last Post: Pedroski55
  Writing string to file results in one character per line RB76SFJPsJJDu3bMnwYM 4 1,597 Sep-27-2022, 01:38 PM
Last Post: buran
  read a text file, find all integers, append to list oldtrafford 12 4,170 Aug-11-2022, 08:23 AM
Last Post: Pedroski55
  How to modify python script to append data on file using sql server 2019? ahmedbarbary 1 1,328 Aug-03-2022, 06:03 AM
Last Post: Pedroski55
  [split] Results of this program in an excel file eisamabodian 1 1,693 Feb-11-2022, 03:18 PM
Last Post: snippsat
  How to save some results in .txt file with Python? Melcu54 4 7,624 May-26-2021, 08:15 AM
Last Post: snippsat
  Running A Parser In VSCode - And Write The Results Into A Csv-File apollo 5 4,916 Jan-14-2021, 08:58 PM
Last Post: snippsat
  Writing unit test results into a text file ateestructural 3 5,008 Nov-15-2020, 05:41 PM
Last Post: ateestructural

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020