2013-03-21 75 views

回答

2

与您的代码的问题是,你忘了关outfileoutfile.close()。按默认Python将所有内容写入缓冲区,当您在outfile上调用close时,将写入该缓冲区(=已刷新)。

0

这里是如何扭转你的线条

lines = '''cat dog house animal 
plant rose tiger tree 
zebra fall winter donkey''' 

lines = "\n".join(lines.split("\n")[::-1]) 

print lines 

#outfile.writelines("\n".join(infile.readlines()[::-1])) 
+0

当'readlines'已经返回一个行列表时,为什么在换行符上分割? – 2013-03-21 19:29:37

+0

@JohnY从我的测试中复制粘贴错误,修复。 – John 2013-03-21 19:34:54

相关问题