[Python] "FileNotFoundError: [Errno 2] No such file or directory" 해결


[Python]

문제상황: 파이썬을 사용하여 프로젝트에서 텍스트 파일을 읽으려고 할 때, 파일을 찾을 수 없어 발생하는 에러입니다. 실무에서 사용될 수 있는 코드 예시는 다음과 같습니다. import os file_path = 'data/sample.txt' with open(file_path, 'r') as file: content = file.read()위 코드를 실행하면 다음과 같은 에러로그가 발생합니다. FileNotFoundError: [Errno 2] No such file or directory: 'data/sample.txt'해결방법: 에러가 수정된 코드와 수정된 부분에 대한 주석을 포함합니다. import os file_path = 'data/sample..


원문링크 : [Python] "FileNotFoundError: [Errno 2] No such file or directory" 해결