Speaking of now, it's more. Until now, the file was read as follows.
f = open("hoge.txt", mode='r')
Various processing
f.close()
You can use *'open' * as it is as described above, but by using *'with' * together, the file being read will be closed automatically even when the program ends.
with open("hoge.txt", mode='r') as f
Various processing
As a memorandum ...
Recommended Posts