다음 코드를 가지고 있으며 오류가 발생합니다 : 파일을 열었음에도 불구하고 닫힌 파일에 대한 I/O 작업.닫힌 파일에 대한 Python I/O 작업, 오류가 발생한 이유는 무엇입니까? 아래 코드
.txt 파일을 만들고 .txt 파일에 사전 값을 쓰고 파일을 닫습니다.
그런 다음 만든 파일에 대해 SHA256 다이제스트를 인쇄하려고합니다.
sys.stdout = open('answers.txt', 'w')
for key in dictionary:
print(dictionary[key])
sys.stdout.close()
f = open('answers.txt', 'r+')
#print(hashlib.sha256(f.encode('utf-8')).hexdigest())
m = hashlib.sha256()
m.update(f.read().encode('utf-8'))
print(m.hexdigest())
f.close()
왜이 오류가 발생합니까? 여기
Traceback (most recent call last):
File "filefinder.py", line 97, in <module>
main()
File "filefinder.py", line 92, in main
print(m.hexdigest())
ValueError: I/O operation on closed file.
전체 오류 추적을 질문에 추가하십시오. –
@KlausD. 편집 됨! –