Python Forum
extracting data from a list in a file
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
extracting data from a list in a file
#1
good morning guys,

I am trying to extract the descriptor in bold in a list (the list is in a file):

This is the content of the file: training_set_sub.txt
[['Verapamil', 'COC1=C(OC)C=C(CCN©CCCC(C#N)(C©C)C2=CC(OC)=C(OC)C=C2)C=C1', 0, 71, '0', '13', '2', 6, 7.0, 0.46, 5.09, '1', '0.60', '5.888', -2.447620829090909, '-7.093', '0'], ['Norverapamil', 'COC1=CC=C(CCNCCCC(C#N)(C©C)C2=CC(OC)=C(OC)C=C2)C=C1OC', 0, 68, '1', '13', '2', 6, 7.0, 0.46, 5.14, '1', '3.06', '5.914', -3.918865, '-7.435', '0']]

What I am doing is:

file = open('training_set_sub.txt','r')
all = file.read().replace("'",'').split('], [')
b = str(all).split(',')
print (b)

for row in all:
    print (b[3])
but this way I obtain:
71
71
and I need to obtain
71
68

Could you help me, please?
Reply


Messages In This Thread
extracting data from a list in a file - by clarablanes - Jan-20-2019, 11:18 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Extracting the correct data from a CSV file S2G 6 248 Jun-03-2024, 04:50 PM
Last Post: snippsat
  Help with to check an Input list data with a data read from an external source sacharyya 3 586 Mar-09-2024, 12:33 PM
Last Post: Pedroski55
  Extracting specific file from an archive tester_V 4 656 Jan-29-2024, 06:41 PM
Last Post: tester_V
  Extracting Data into Columns using pdfplumber arvin 17 6,039 Dec-17-2022, 11:59 AM
Last Post: arvin
  Extracting Specific Lines from text file based on content. jokerfmj 8 3,221 Mar-28-2022, 03:38 PM
Last Post: snippsat
  Extracting Data from tables DataExtrator 0 1,202 Nov-02-2021, 12:24 PM
Last Post: DataExtrator
  Why changing data in a copied list changes the original list? plumberpy 3 2,321 Aug-14-2021, 02:26 AM
Last Post: plumberpy
  extracting data ajitnayak1987 1 1,612 Jul-29-2021, 06:13 AM
Last Post: bowlofred
  Extracting and printing data ajitnayak1987 0 1,461 Jul-28-2021, 09:30 AM
Last Post: ajitnayak1987
  Extracting Elements From A Website List knight2000 2 2,438 Jul-20-2021, 10:38 AM
Last Post: knight2000

Forum Jump:

User Panel Messages

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