1

I need to build a python code to store the python numbers that are in a file. The lines where those numbers are starts with a word "Mark" and then I have blank spaces and three columns of numbers, like this:

Mark    1     2    3 
Mark    4     4    6

Where the number of blank spaces between the numbers are not known. I know how to read the file line by line searching for the word line:

with open("doc.dat") as file:
    for line in file:
        if line.startswith("Mark"):

But I do not know how to call the condition for extracting the numbers and passing them to a variable. How can this be done?

Thanks in advance

Paul Roberts
  • 119
  • 6

1 Answers1

2

u can extract numbers with this code :

with open("doc.dat") as file:
    for line in file:
        if line.startswith("Mark"):
            line = line.strip()[4:].strip()
            numbers_list = []
            for letter in line:
                if letter != ' ':
                    numbers_list.append(int(letter))
            print(numbers_list) #its list of numbers