You could use the fileinput
module:
(您可以使用fileinput
模块:)
import fileinput
for line in fileinput.input():
pass
fileinput
will loop through all the lines in the input specified as file names given in command-line arguments, or the standard input if no arguments are provided.
(fileinput
将循环输入指定为命令行参数中给定的文件名的输入中的所有行,如果没有提供参数,则返回标准输入。)
Note: line
will contain a trailing newline;
(注意: line
包含尾随换行符;)
to remove it use line.rstrip()
(删除它使用line.rstrip()
)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…