文件操作小知识点补充

有些文件太大,不能直接读写,需要一行一行的读,用一个for循环
# f = open("log", mode="r+", encoding="utf-8")
#
# for line in f:
# print(line)
#
# f.close()
with open 打开文件操作可以自动关闭,不需要加f.close()

# with open("log", mode="r+", encoding="utf-8") as f:
# print( f.read())
with open("log", mode="r+", encoding="utf-8") as f1,open("123", mode="r+", encoding="utf-8"):
f1.read()

猜你喜欢

转载自www.cnblogs.com/jly1/p/9570585.html