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()
如何在input.txt
之后删除instance.save()
文件的所有内容?
答案 0 :(得分:2)
使用file.truncate
:
text_file.truncate(0)
file.truncate
上的帮助:
>>> print file.truncate.__doc__
truncate([size]) -> None. Truncate the file to at most size bytes.
Size defaults to the current file position, as returned by tell().