加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Python > 正文

如何在python中将搁置文件清空?

发布时间:2020-12-16 23:17:46 所属栏目:Python 来源:网络整理
导读:我创建了一个搁置文件并插入了一个字典数据.现在我想清理搁置文件以重用为干净文件. import shelvedict = shelve.open("Sample.db")# insert some data into sample.dbdict = { "foo" : "bar"}#Now I want to clean entire shelve file to re-insert the dat
我创建了一个搁置文件并插入了一个字典数据.现在我想清理搁置文件以重用为干净文件.
import shelve
dict = shelve.open("Sample.db")
# insert some data into sample.db
dict = { "foo" : "bar"}

#Now I want to clean entire shelve file to re-insert the data from begining.

解决方法

Shelve的行为就像字典一样,因此:
dict.clear()

或者,您可以随时删除该文件,并让搁置创建一个新文件.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读