mingyuezhao01 2017-06-10 16:21 采纳率: 0%
浏览 1552

关于dbm.error 的问题,求解,编程小白

from datetime import datetime

import shelve,os

class userdatabase(object):

def init(self,dbfile):

self.db = {}

if os.path.exists(dbfile):

self.db = shelve.open(dbfile, 'c')

self.dbfile = dbfile

self.flag = False

def __del__(self):  
    data = shelve.open(self.dbfile, 'c')    
    data.update(self.db)    
    data.close()  

def login(self,user,pwd):  
    if user not in self.db:  
        self.flag = False  
    elif self.db[user][0] == pwd:  
        self.db[user][1] = datetime.now()  
        self.flag = True  

def deluser(self,user):  
    if self.flag:  
        self.db.pop(user)  
    else:  
        print ('login first')  

def updateuser(self,user,pwd):  
    if self.flag:  
        self.db[user] = [pwd,datetime.now()]  
    else:  
        print ('login first')  

def listall(self):  
    if self.flag:  
        for user in self.db:  
            print( user, self.db[user][0], self.db[user][1])
    else:  
        print( 'login first')


a = userdatabase('userdata.txt')
Traceback (most recent call last):
File "", line 1, in
a = userdatabase('userdata.txt')
File "C:\Users\Administrator\Desktop\用户注册.py", line 16, in init
self.db = shelve.open(dbfile, 'c')
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python36\lib\shelve.py", line 243, in open
return DbfilenameShelf(filename, flag, protocol, writeback)
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python36\lib\shelve.py", line 227, in init
Shelf.__init__(self, dbm.open(filename, flag), protocol, writeback)
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python36\lib\dbm__init__.py", line 88, in open
raise error0
dbm.error: db type could not be determined

  • 写回答

1条回答 默认 最新

  • cyliu_test 2017-06-21 12:03
    关注

    a = userdatabase('userdata.txt')
    去掉扩展名.txt试试

    评论

报告相同问题?

悬赏问题

  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥200 uniapp长期运行卡死问题解决
  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?
  • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?
  • ¥15 乘性高斯噪声在深度学习网络中的应用
  • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 C++ 头文件/宏冲突问题解决