[Python] How do I find a string after finding a different string in a large text file?

Discussão em 'Python' iniciado por Stack, Março 19, 2025.

  1. Stack

    Stack Membro Participativo

    I have a large text file and would like to use Python extract a line after matching a string in a preceding line. I can easily match the beginning string of a line with startswith(), but I want to find the first occurrence of a string after that position. Here is an example of the text in my file:

    Test results
    Description
    Time 0.000
    c-14 0.0000E+00


    In other words, I can easily find the "Test results" string, but then I want to find the next or skip to the line that starts with "c-14" and read some numbers after it. I've tried a few things like re.findall() and next(), but I might have missed something. Thanks and let me know what you think.

    Continue reading...

Compartilhe esta Página