f.write(line + ''' ''')
原代码
line = input() while line: with open('test.txt','a') as f: f.write(line + ''' ''') line = input()
收起
是不是每次运行追加5行数据?以下代码,过虑了空行,回车前有内容才计1次,5次后退出
count = 0 while count<5: line = input() if line: #判断空行,不要排除空行就去掉 with open('test.txt','a') as f: f.write(line + '\n') count += 1
报告相同问题?