【发布时间】:2015-04-12 04:49:44
【问题描述】:
我有这个功能:write_reversed_file(input_filename, output_filename) 将给定输入文件的内容以相反的顺序写入给定的输出文件。我只需要将输出写入文件(output_filename)而不是终端(python shell)。
我唯一缺少的部分是将输出存储到文件中。 我成功地完成了倒车线部分。
def write_reversed_file(input_filename, output_filename):
for line in reversed(list(open(filename))):
print(line.rstrip())
【问题讨论】:
-
Shell 输出重定向,如
python foo.py > output.txt,可能就足够了。
标签: file python-3.x storing-information