python - 如何在搁置中设置价值
问题描述
我想将字典存储在搁置中,也想将数据放入其中。我怎样才能做到这一点?
import shelve
s = shelve.open("test")
s['flag'] = {}
解决方案
您不能直接编辑值,因此您必须更新副本然后重置它:
import shelve
s = shelve.open("test")
s['flag'] = {}
temp = s['flag']
temp['foo'] = 'bar'
s['flag'] = temp
你不能做
s['flag']['foo'] = 'bar'
直接因为s['flag']
返回一个副本
推荐阅读
- spartacus-storefront - 如果重定向的 URL 中没有指定语言,则重定向到默认语言 - Spartacus
- angular - Angular CDK - 滚动时覆盖附加到目标
- reactjs - 用 react-image-gallery 反应 jsfiddle
- firebase - Firestore 集合组更新文档
- bazel - 使用没有 `--compilation_mode opt` 标志的 bazel 构建 bazel 如何影响性能?
- windows - 带有 OFFSET 标签的汇编 PUSH 指令
- fortran - 在 Mac Big Sur 上写入标准输出时出现 gfortran 运行时错误
- list - 在 SwiftUI 中实现多个标题
- android - 即使添加了屏幕方向锁定,Android 屏幕方向
- javascript - 如何在 Typescript 中使用类型化变量作为具有相同名称的类型?