Question: ```
def openFood():
    with open("FoodList.txt")  as f:
                lines = f.readlines()
                for line in lines:
                    if 'Food' in line:
                        print(f.next())
openFood()

```

I want it where when it sees a certain header like 'Food' It will print the line below it. I cant seem to make it work. The text file will be like

```
Food
Apple
Cal 120
Protein 12
Fat 13 
Carb 23

```

Answer: 
Just use the index.

```
def openFood():
    with open("FoodList.txt")  as f:
        lines = f.readlines()
        for i in range(len(lines)-1):
            if 'Food' in lines[i]:
                print(lines[i+1])
openFood()

```
Reading a file one line at a time can be beneficial if the file is very large. This code will not load the full file into memory, but only one line at a time:

```
def openFood():
    with open("FoodList.txt") as f:
        line = f.readline()
        while line:
            if 'Food' in line:
                print(f.readline())
            line = f.readline()

openFood()

```

Result:

```
Apple

```

**Note**: This method will be a lot slower for smaller files, than reading the contents into memory using the `readlines()` method.