How do I print the content of a .txt file in Python?

前端 未结 9 981
慢半拍i
慢半拍i 2020-12-13 18:28

I\'m very new to programming (obviously) and really advanced computer stuff in general. I\'ve only have basic computer knowledge, so I decided I wanted to learn more. Thus I

9条回答
  •  南笙
    南笙 (楼主)
    2020-12-13 19:14

    with open("filename.txt", "w+") as file:
      for line in file:
        print line
    

    This with statement automatically opens and closes it for you and you can iterate over the lines of the file with a simple for loop

提交回复
热议问题