So, not exactly having issues with my coding, but a general questions for any of experienced Python gurus out there!
I guess there are 2 ways for writing/reading file. One method is opening a file, writing data and closing it. The other “with” “as” method opens and closes automatically…So the question is…
Why would anyone use ( 3 lines of code!!)
write_file = open(“text.txt”, “w”)
write_file.write(“Not closing files is VERY BAD.”)
OVER (2 lines of code that a ALSO closes automagically)
with open(“text.txt”, “w”) as textfile:
Can anyone explain why we shouldn’t just use the second method all the time? Why does the first method even exist in the first place…?