Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
data.txtファイルからすべてのデータを削除したい:
どうやってやるの?
with open('data.txt', 'w'): pass
これにより、 の内容が削除され'data.txt'、空のファイルが残ります。(これは Python3 でも機能します)。
'data.txt'
ただ行う:open(file,'w').close()
open(file,'w').close()
open(file, 'w')あなたのために働くことができます。ファイルを閉じるか、with.
open(file, 'w')
with