File manipulation small knowledge points supplement

Some files are too large to read and write directly. They need to read one line by line, using a for loop.
# f = open("log", mode="r+", encoding="utf-8")
#
# for line in f:
# print(line)
#
# f.close()
with open Open file operation can be automatically closed without adding 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()

Leave a Reply

Your email address will not be published. Required fields are marked *