Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/307.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何在instance.save()之后删除input.txt文件的所有内容?_Python - Fatal编程技术网

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)