【发布时间】:2012-07-13 15:10:53
【问题描述】:
我正在将“文章”的内容写入文本文件。
源文件:
lol hi
lol hello
lol text
lol test
Python:
for line in all_lines:
if line.startswith('lol '):
mystring = line.replace('lol ', '').lower().rstrip()
article = 'this is my saved file\n' + mystring + '\nthe end'
这是保存到 txt 文件的内容:
this is my saved file
test
the end
这是我要保存到 txt 文件的内容:
this is the saved file
hi
hello
test
text
the end
【问题讨论】: