Extracting Value from List

Hi,

I want to extract just a single value from a .dat file, so far I have managed to extract the value I want but my adding individual strings together. It is very clunky, so looking for a smoother method which will just give me the first value in the row.

Thanks
Screenshot 2024-07-25 091137

Please post code and output examples as text not screen shots using the </> button, pre-formatted text.

Why do you split on \t? It seems that your data is seperated by spaces.
Does GL[-1].split() give you a list that you can work with?

The split() function uses blank (space) as the default delimiter and returns a list of blank separated strings. See tutorial. So your question is answered by
newQ = GL[-1].split()[0]
Also, you want to be aware that list and strings both use [ ] to allow indexing.

That is very helpful thank you.

I need to do the same thing for a different list but contains numbers and words.

I need to extract the 4th and 5th indexed values (0.006265 & 1.295826). Tried method above but not working the same way. Any suggestions?

Code:

        PyFluent_List = open(PATH2BOLIST, "r")
        PF = PyFluent_List.readlines()
        newVal_ = PF[-1].split()[0]
        print(newVal_)
        drag = newVal_[4]
        print(drag)
        lift = newVal_[5]
        print(lift)

Output:

DP10,-300,0.951057,0.309017,0.006265,1.295826,No,Yes,Updated
,
-

Thanks

Problem resolved, thank you.