【发布时间】:2010-09-25 06:27:27
【问题描述】:
使用 python 从文本文件中读取行时,通常需要在处理文本之前截断行尾字符,如下例所示:
f = open("myFile.txt", "r")
for line in f:
line = line[:-1]
# do something with line
有没有一种优雅的方式或习语来检索没有结束行字符的文本行?
【问题讨论】:
-
这能回答你的问题吗? How to read a file without newlines?
标签: python