20190218-学习python使用shelve遇到raise error, "db type could not be determined"
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了20190218-学习python使用shelve遇到raise error, "db type could not be determined",小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含1947字,纯文字阅读大概需要3分钟。
内容图文
![20190218-学习python使用shelve遇到raise error, "db type could not be determined"](/upload/InfoBanner/zyjiaocheng/841/175c5e91d03e45fcb6dbe2cdc92fcd62.jpg)
照书上敲代码,运行了提示raise error, "db type could not be determined",现场如下:
ubuntu-vm:~/code/massageboard$ python Python 2.7.6 (default, Nov 13 2018, 12:45:42) [GCC 4.8.4] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import shelve DATA_FILE='guestbook.dat' >>> DATA_FILE='guestbook.dat' >>> >>> def save_data(name,comment,create_at): ... database=shelve.open(DATA_FILE) ... if 'greeting_list' not in database: ... greeting_list=[] ... else: ... greeting_list=database['greeting_list'] ... greeting_list.insert(0,{ ... 'name':name, ... 'comment':comment, ... 'create_at':create_at, ... }) ... database['greeting_list']=greeting_list ... database.close() ... >>> import datetime >>> save_data('test','test comment',datetime.datetime(2019,02,18,10,0,0)) Traceback (most recent call last): File "<stdin>", line 1, in <module> File "<stdin>", line 2, in save_data File "/usr/lib/python2.7/shelve.py", line 239, in open return DbfilenameShelf(filename, flag, protocol, writeback) File "/usr/lib/python2.7/shelve.py", line 223, in __init__ Shelf.__init__(self, anydbm.open(filename, flag), protocol, writeback) File "/usr/lib/python2.7/anydbm.py", line 82, in open raise error, "db type could not be determined" anydbm.error: db type could not be determined >>>
故障排除过程:
ubuntu-vm:~/code/massageboard$ ls guestbook.dat guestbook.py guestbook.pyc index.html main.css __pycache__ ubuntu-vm:~/code/massageboard$ rm guestbook.dat #删除数据存储文件 ubuntu-vm:~/code/massageboard$ ls guestbook.py guestbook.pyc index.html main.css __pycache__
ubuntu-vm:~/code/massageboard$ python Python 2.7.6 (default, Nov 13 2018, 12:45:42) [GCC 4.8.4] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import datetime >>> from guestbook import save_data >>> save_data('test','test comment',datetime.datetime(2019,02,18,10,0,0)) >>>
内容总结
以上是互联网集市为您收集整理的20190218-学习python使用shelve遇到raise error, "db type could not be determined"全部内容,希望文章能够帮你解决20190218-学习python使用shelve遇到raise error, "db type could not be determined"所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。