私はこのコード- 私が欲しいPython27
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+
モードは最高の私に合っていますが、それは私だけがa+
モードでは、ファイルの末尾に
を書き込むことができますことを何をするか、私はすぐにファイルを開いた後、このf.seek(0)
を持っていました、それは影響を与えない、それはファイルの開始を求めることはありません。
@StamKaly、どこで取得できましたか? –
@AhsanulHaque彼は彼のコメントを削除しましたhaha – Umair