How to avoid new line in readline() function in python 3x?
This question already has an answer here:
由于你的内容已经包含你想要的换行符,所以通过使用可选的end
参数告诉print()
函数不要添加任何内容:
def print_one_line(line_number,f):
print(line_number,f.readline(), end='')
而不是跳过输出的换行符,您可以从输入中去除它:
print(line_number, f.readline().rstrip('n'))
Beside the other ways, you could also use:
import sys
sys.stdout.write(f.readline())
Works with every Python version to date.
链接地址: http://www.djcxy.com/p/77218.html上一篇: 如何水平打印字符?