为什么shelve会失败?

来源:互联网 发布:剑灵男灵族捏脸数据 编辑:程序博客网 时间:2024/04/20 03:05

先看代码:

class Empty:  passdef save_obj():  x = Empty  x.name='hello'  x.value = 343    with shelve.open('empty') as db:    db['x']=x    def load_obj():  with shelve.open('empty') as db:    x = db['x']    print(x.name, x.value)


当我第一次运行:

save_obj()load_obj()
结果正常显示。


但是第二次运行

load_obj()
却抛出异常:

AttributeError: type object 'Empty' has no attribute 'name'

这是为什么?


原创粉丝点击