[Python] Read from a File in Python

Using the open function, and the as and with keywords, we'll open up and read from a file. At the end of this lesson, you will be able to loop through the lines of text in a file, process the text in Python, and then print them to the terminal.

 

with open("input.txt") as text:
    for line in text:
        print("-------")
        print(line)

 

posted @ 2020-05-13 18:57  Zhentiw  阅读(159)  评论(0编辑  收藏  举报