[Tutor] Extract Names from string
David Rock
david at graniteweb.com
Tue Aug 3 11:38:29 EDT 2021
* Stephen P. Molnar <s.molnar at sbcglobal.net> [2021-08-03 10:52]:
> I appreciate your answer, but I'm afraid that I was not clear in what I want
> to do.
>
> I read the list of names using:
>
> f = open('Ligand.list_1.csv', 'r') # 'r' = read
> lines = f.read()
> print(lines),
> f.close()
>
> Which results in lines str 116:
>
> "CaffeicAcid","Cannflavin-A","Cannflavin-B","Cannflavin-C","Diosmetin","Echinacoside","Hesperetin","L-CichoricAcid"
>
> My problem is that I want to iteratively extract each name which I need for
> an inner loop which out carries out the next calculation in my computational
> pipeline.
As already mentioned, look into the CSV module. After all, you are already reading from a CSV file, so you might as well leverage the tools available in it to parse the line.
https://docs.python.org/3/library/csv.html
It will also help if you are dealing with a file that has multiple lines later on.
--
David Rock
david at graniteweb.com
More information about the Tutor
mailing list