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()
如何在instance.save()
之后删除input.txt
文件的所有内容?
最佳答案
使用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().
关于python - 如何在instance.save()之后删除input.txt文件的所有内容?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16820485/