我试图将一个JSON对象加载到DictProxy
对象中,但没有看到一种“简单”的方法。我可以很容易地将JSON加载到字典中,但是如果我试图将这个dict
复制到DictProxy
,它将保持为dict
(这对我这样做很有意义)。我可以创建一个空的DictProxy
,然后构建一个函数来遍历我的dict
并填充{DictProxy
的文档,所以我不太确定它与dict
共享(或不共享)哪些特性。有没有一种干净的方法可以做到这一点,或者我应该构建一个遍历dict
并构建{
代码:
import multiprocessing
import json
def main():
with open(r"c:\path\to\my.json") as js:
my_dict = json.load(js)
print type(my_dict) # <type 'dict'>
manager = multiprocessing.Manager()
my_dict_proxy = manager.dict()
print type(my_dict_proxy) # <class 'multiprocessing.managers.DictProxy'>
my_dict_proxy = my_dict
print type(my_dict_proxy) # <type 'dict'>
if __name__ == "__main__":
main()
DictProxy
提供一个update()
方法。您应该能够这样做:相关问题 更多 >
编程相关推荐