[Tutor] Extract Names from string
Stephen P. Molnar
s.molnar at sbcglobal.net
Tue Aug 3 10:52:12 EDT 2021
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.
Sorry for the confusion.
On 08/03/2021 09:29 AM, nathan Smith wrote:
> So if I've understood this right you'd have a list of elements like this:
>
> st="\"hydrogen\", \"helium\""
>
>
> That being the case could you not just do something like:
>
> splitted=st.split(",")
>
> for x in range(len(splitted)):
>
> splitted[x]=splitted[x][1:-1]
>
>
> And there you have it?
>
> A list of names without quotes?
>
> Nathan
>
> On 03/08/2021 14:08, Stephen P. Molnar wrote:
>> I have a project which generates a large number of data files and
>> have pyhon scrip;t that does most of the pre- and post-processing.
>> However, I have one problem which has not succumbed to Googling.
>>
>> I have a list of chemical names which I can load as a string of the
>> form:
>>
>> "name1","name2", . . .
>>
>> Unfortunately, the names are not the same length which precludes
>> extracting each name by indexing.
>>
>> My question is ho w to extract individual names?
>>
>> Thanks in advance.
>>
> _______________________________________________
> Tutor maillist - Tutor at python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
--
Stephen P. Molnar, Ph.D.
614.312.7528 (c)
Skype: smolnar1
More information about the Tutor
mailing list