with open("example.txt", "r") as f: lines = f.readlines() for line in lines: print(line.strip())
import io string = "This is a test.\nHere is another line.\nAnd one more." stream = io.StringIO(string) lines = stream.readlines() for line in lines: print(line.strip())In this example, we start with a string `string` containing multiple lines of text. We create an `io.StringIO` object `stream`, which allows us to treat the string as a file-like stream. We then use `readlines()` to read all the lines in the stream and store them in the `lines` variable. Finally, we loop through the lines and print each one, stripping any whitespace characters from the beginning and end of the line using the `strip()` method. Both of these examples use the `io` package library.