Python 如何在instance.save()之后删除input.txt文件的所有内容?
如何在Python 如何在instance.save()之后删除input.txt文件的所有内容?,python,Python,如何在instance.save()之后删除input.txt文件的所有内容?使用file.truncate: text = "sample sample" text_file = open("input.txt", "r+b") text_file.write(text) instance.src_after = File(text_file) instance.save() text_file.close() text_file.truncate(0) 有关文件的帮助。截断: text
instance.save()
之后删除input.txt
文件的所有内容?使用file.truncate
:
text = "sample sample"
text_file = open("input.txt", "r+b")
text_file.write(text)
instance.src_after = File(text_file)
instance.save()
text_file.close()
text_file.truncate(0)
有关文件的帮助。截断:
text = "sample sample"
text_file = open("input.txt", "r+b")
text_file.write(text)
instance.src_after = File(text_file)
instance.save()
text_file.close()
text_file.truncate(0)
使用文件。截断:
text = "sample sample"
text_file = open("input.txt", "r+b")
text_file.write(text)
instance.src_after = File(text_file)
instance.save()
text_file.close()
text_file.truncate(0)
有关文件的帮助。截断:
text = "sample sample"
text_file = open("input.txt", "r+b")
text_file.write(text)
instance.src_after = File(text_file)
instance.save()
text_file.close()
text_file.truncate(0)