开发者

write a paragraph to a file

Ok this is simple, I want to write a huge paragraph of text to a file. I know I can do

f=open("blah.txt",'w')
f.write("blah blah \n")
f.write("bla blah blah ")
f.close()

but what is 开发者_JS百科a little more elegant solution?


f.write("""I’ve got a lovely bunch of coconuts
There they are all standing in a row
Big ones, small ones, some as big as your head
Give them a twist a flick of the wrist
That’s what the showman said""")


You can use the 3 quote string declaration like so.

>>> a = '''blah blah blah blah
blah blah blah blah
blah blah blah blah'''
>>> print(a)
blah blah blah blah
blah blah blah blah
blah blah blah blah
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜