[오픈] [1] 에서 내장 함수를 파이썬 지정하십시오. 정확한 차이점은 모드 'w', 'a', 'w+', 'a+' 및 'r+'?
특히 이러한 모든 문서 수 있음을 말해주는 것이라고 이 파일을 쓰는 파일이므로 열었든 ";;;;, 및 " appending" " writing" updating". 구체적으로 어떤 정의되어 있지 않지만, 이 용어는 짓궂군요.
오프닝 모드는 경우와 동일하게 C 표준 라이브러리 함수 () '' fopen .
BSD 'fopen' 마 페이지 eventtest 솔리드로 다음과 같습니다.
<! - 언어: > 없음 -;
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.
그냥 같은 정보, 표 형태로
| r r+ w w+ a a+
------------------|--------------------------
read | + + + +
write | + + + + +
write after seek | + + +
create | + + + +
truncate | + +
position at start | + + + +
position at end | + +
여기서 의미가 있다. (그냥 방지하기 위해 오해)
create - 파일이 생성됩니다 아직 존재하지 않는 경우
참고: 'a' 와 'a+' 말 '' 선택특수 말라실로 파일 - 항상 덮어쓰기/추가 무시합니다. 브트와. 흥미로운 비헤이비어를 win7 에서 열린 'a+' 새로운 파일 / python2.7, 적어도 내가 있는 모드. '쓰기 (& # 39, aa& # 39;). 말라실로 (0, 0); 읽기 (1). 쓰기 (& # 39, b& # 39;) '-' 쓰기 '는 두 번째 무시됨 '쓰기 (& # 39, aa& # 39;). 말라실로 (0, 0); 읽기 (2). 쓰기 (& # 39, b& # 39;) '-' 초 '쓰기' 감사 'IOError
옵션 동일합니다. http://www.manpagez.com/man/3/fopen/";;; a href = " < > fopen function< /a>. c 표준 라이브러리에서:
'w' 는 이미 잡깐 있는모든 덮어쓰므로 잘라냅니다 파일
'a' 는 이미 그 파일에 대한 추가 있는모든 관용으로충만하신 첨부됩니다.
'w+, 파일을 읽을 수 있는' 읽고 쓰기 위한 열었든 잘라내는 뒤로를 what& # 39 에 기록될 뿐만 아니라 파일
'a+' 에 모두 사용할 수 있는 파일의 추가와 판독값 열었든 첨부하려면 또한 그 내용을 읽기
I hit & # 39, 이 때 사용하는 이유에 모드 # 39 w+& 위해 애쓴다. # 39, & # 39, w& 대對. 결국, 일부 방금 테스트. # 39, & # 39, 내가 don& t 지켜보리니 목적은 모드 등 많은 w+& # 39, 두 경우 모두 파일은 깎은 꼴입니다. # 39, & # 39, 읽을 수 있습니다 그런데 w+& 의해 쓴 이후 뒤로를 있다. # 39, & # 39 함께 했는데, 이 경우 모든 판독값 w& ioerror 오르게 된다. # 39, & # 39 와 모드를 사용하지 않고 판독값 말라실로 w+&. # 39, 아무것도 없는 것 때문에 isn& 넘겨 작성한 후 파일포인터는 있는 것입니다.
내 생각에 이것은 고려해야 할 중요한 크로스 플랫폼을 엑서큐션 시아, 예를 들어 있다. )
>. Windows 에서 b& # 39, & # 39. 이진 파일을 열어 덧붙여집니다 모드 모드 모드 # 39, & # 39 와 같은 도왔으매 또한 rb& # 39, & # 39, & # 39,, 그리고 wb& r+b& # 39;. 파이썬 Windows 의 차이점은 텍스트 및 바이너리 파일을 만듭니다. 텍스트 파일은 자동으로 이 행 끝 문자를 변경할 때 데이터를 읽고 쓰는 약간 있다. 이 수정 배후에 있을 수 있지만 파일 데이터는 이진 데이터를 ASCII 텍스트 파일 과태료를 EXE 파일을 JPEG 나 있는 것 같다. 이진 파일을 읽기 · 쓰기 등 모드를 사용할 때 주의해야 합니다. Unix 에서 b& # 39, & # 39 는 안아플거야 첨부하려면. 이 모드를 사용할 수 있도록 모든 it 플랫폼 독립적으로 이진 파일.
이것은 직접 인용 위치 [파이썬 소프트웨어 재단 2.7.x] (https://docs.python.org/2/tutorial/inputoutput.html # 파일 읽기 및 쓰기).