with open("/Users/thunder/Desktop/src/info.txt", "r") as f:
txt_read = f.read()
print(txt_read,"###########################")
f.seek(0)
txt_readline = f.readline()
print(txt_readline)
f.seek(0)
txt_readlines = f.readlines()
print(txt_readlines)
输出结果:
I wish you all I ever wanted for you, I wish you the best.我希望你不负我的期望,愿你一切安好。
Losing all hope was freedom.
彻底绝望就是真正的自由。
The world is a fine place, and worth fighting for.
这世界是个好地方,值得为之奋斗。
Life takes on the meaning that you give it.
你赋予生活什么,生活就是什么样。
############read###############
I wish you all I ever wanted for you, I wish you the best.我希望你不负我的期望,愿你一切安好。
############readline###############
['I wish you all I ever wanted for you, I wish you the best.我希望你不负我的期望,愿你一切安好。\n', 'Losing all hope was freedom.\n', '彻底绝望就是真正的自由。\n', '\n', 'The world is a fine place, and worth fighting for.\n', '这世界是个好地方,值得为之奋斗。\n', 'Life takes on the meaning that you give it.\n', '你赋予生活什么,生活就是什么样。\n'] ############readlines###############
显然: read是一次读取全文。
readline 是读一行,需要一行一行处理的时候,我们可以来for循环
readline 是读取每行,并存储在列表中,这样我们可以用列表的一些行数来操作
待完善~~~