20190218-学习python使用shelve遇到raise error,…
2019-02-20 00:46:08来源:博客园 阅读 ()
照书上敲代码,运行了提示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)) >>>
原文链接:https://www.cnblogs.com/coffeebox/p/10395455.html
如有疑问请与原作者联系
标签:
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有
上一篇:#3 不使用循环输出1到100
下一篇:Python 反射
- python3基础之“术语表(2)” 2019-08-13
- python3 之 字符串编码小结(Unicode、utf-8、gbk、gb2312等 2019-08-13
- Python3安装impala 2019-08-13
- 小白如何入门 Python 爬虫? 2019-08-13
- python_字符串方法 2019-08-13
IDC资讯: 主机资讯 注册资讯 托管资讯 vps资讯 网站建设
网站运营: 建站经验 策划盈利 搜索优化 网站推广 免费资源
网络编程: Asp.Net编程 Asp编程 Php编程 Xml编程 Access Mssql Mysql 其它
服务器技术: Web服务器 Ftp服务器 Mail服务器 Dns服务器 安全防护
软件技巧: 其它软件 Word Excel Powerpoint Ghost Vista QQ空间 QQ FlashGet 迅雷
网页制作: FrontPages Dreamweaver Javascript css photoshop fireworks Flash