如何删除Python 3中的3个搁置文件?
如果我知道书架的名称,如何删除它?
I wrote a few unittests with shelve at http://code.google.com/p/filecache/ and python 2 saves exactly the filename I specifiy in shelve.open() but in python 3 I get 3 different files "bak", "dat" and "dir". So before the tests start I want to erase these files but I don't know if I have any guarantee as to their filename or extension.
How can I erase a shelve if I know it's name?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您获得的扩展取决于使用的数据库后端。 Python 2 和 Python 3 之间的默认值可能有所不同,但也可能是您的环境中可用的数据库接口之间存在差异。
因此,不,您无法保证扩展,除非您使用特定的实现,即 BsdDbShelf 或 DbfilenameShelf。您可以在 tempfile 创建的临时目录中指定一个文件,然后删除 while 目录。
What extensions you get depends on which database backend is used. It's possible that the default differs between Python 2 and Python 3, but it can also be a difference between what database interfaces are available in your environment.
So no, you don't have a guarantee to the extensions, unless you use a specific implementation, ie either BsdDbShelf or DbfilenameShelf. You could probably specify a file in a temporary directory created by tempfile, and then delete the while directory.
我使用 shelve 因为 tempFile 和 dict[] 对象无法跨模块持久化。正如您所发现的,调用 .clear() 不会清除磁盘上持久对象的内容,退出后会在磁盘上留下填充的 r+w 文件。 (类似于释放后使用漏洞)您可以在使用完毕后删除搁置:
I use shelve because tempFile and dict[] objects cannot persist across modules. As you have discovered, calling .clear() does not clear content from the persistent object on disk, leaving a populated r+w file on disk after exit. (Similar to a use-after-free vulnerability) You can delete the shelve when finished using: