본문 바로가기
파이썬

파이썬 내장 개방 기능에서 모드 a, a +, w, w + 및 r +의 차이점은 무엇입니까?

by º기록 2021. 1. 26.
반응형


특히, 문서는 이들 모두가 파일에 쓰기를 허용하고 구체적으로 "추가", "쓰기"및 "업데이트"를 위해 파일을 여는 것을 의미하지만 이러한 용어의 의미를 정의하지는 않습니다.

 

해결 방법

 

열기 모드는 C 표준 라이브러리 함수 fopen () 의 경우와 정확히 동일합니다.


 The argument mode points to a string beginning with one of the following
 sequences (Additional characters may follow these sequences.):

 ``r''   Open text file for reading.  The stream is positioned at the
         beginning of the file.

 ``r+''  Open for reading and writing.  The stream is positioned at the
         beginning of the file.

 ``w''   Truncate file to zero length or create text file for writing.
         The stream is positioned at the beginning of the file.

 ``w+''  Open for reading and writing.  The file is created if it does not
         exist, otherwise it is truncated.  The stream is positioned at
         the beginning of the file.

 ``a''   Open for writing.  The file is created if it does not exist.  The
         stream is positioned at the end of the file.  Subsequent writes
         to the file will always end up at the then current end of file,
         irrespective of any intervening fseek(3) or similar.

 ``a+''  Open for reading and writing.  The file is created if it does not
         exist.  The stream is positioned at the end of the file.  Subse-
         quent writes to the file will always end up at the then current
         end of file, irrespective of any intervening fseek(3) or similar.

 

참조 페이지 https://stackoverflow.com/questions/1466000

 

 

반응형

댓글