引用自身中的字典 [英] Reference a dictionary within itself
本文介绍了引用自身中的字典的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否可以从同一词典中的词典条目中获取值? 我想建立一个目录列表,同时引用以前添加的目录.
Is it possible to get a value from a dictionary entry, within that same dictionary? I'd like to build up a list of directories whilst referencing previously added directories..
common_dirs = {
'root': '/var/tmp',
'java_path': os.path.join(dict.get('root'), 'java'),
'application_path': os.path.join(dict.get('java_path'), 'my_app')
}
推荐答案
为什么不更新字典:
my_dict = {'root': '/var/tmp'}
my_dict.update({'file': os.path.join(my_dict.get('root'), 'file')})
请勿使用dict
作为名称.您稍后可能需要真正的dict
内置.
Don't use dict
as a name. You may need the real dict
builtin later on.
这篇关于引用自身中的字典的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文