with codecs.open("file.json", mode='a+', encoding='utf-8') as f:
내가 원하는 코드가 있습니다
1)가 존재하지 않는 경우 파일을 작성을, 파일의 시작 부분부터 쓰기 시작합니다.
2) 존재하는 경우 먼저 읽은 다음 잘라내어 내용을 작성하십시오.
나는이 곳``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.
a+
모드가 나를 가장 잘 맞는 있지만 발견 그것은 단지 제가 파일을 연 후 즉시 f.seek(0)
이 a+
모드로
, 파일의 마지막에 기입 할 것을 무엇 ,하지만 영향을 미치지 않습니다, 그것은 파일의 시작을 추구하지 않습니다.
@StamKaly, 어디서 얻었습니까? –
@AssanulHaque 그는 그의 코멘트를 삭제했다 haha – Umair