Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
append my results to a file
#1
good morning guys,

I need help:

I have done a program to obtain some data and then I have to append this data to the original file. My original file is something like this (with hundred more lines):

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

I need to take each third entry (in bold), process it to obtain a data and append this value to the original file, separated by comma.
I show you my program below. I am able to obtain the values and I see them on the screen but I don't find the way to append them to the original file. Could you help me with this, please?

import os
import subprocess
path_input = '/home/c.blanes/pgp/training.txt'
obabel = '/usr/bin/obabel '
 
f = open(path_input, 'r')

for line in f.readlines():

	smiles = line.split(',')[2].strip('\n')
	print(smiles)
	
	launch = obabel + '-:\'%s\' -otxt --append TPSA'%(smiles)
	print (launch)
	subprocess.call(launch, shell=True)
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,698 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