Occurs when trying to open a file that does not exist or has an incorrect path.
with open("data.txt", "r") as f:
content = f.read()
print(content)FileNotFoundError: [Errno 2] No such file or directory: 'data.txt'
with open("data.txt", "w") as f:
f.write("hello")
with open("data.txt", "r") as f:
content = f.read()
print(content)Tried to open the file, but it wasn’t in the folder I was running from.
Related case: https://pyai.io/en/python/basic/file-io/