How to read a file without newlines?

前端 未结 9 1637
广开言路
广开言路 2020-11-21 21:03

In Python, calling

temp = open(filename,\'r\').readlines()

results in a list in which each element is a line in the file. It\'s a little st

9条回答
  •  南旧
    南旧 (楼主)
    2020-11-21 21:07

    I think this is the best option.

    temp = [line.strip() for line in file.readlines()]
    

提交回复
热议问题