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')
}
Why not update the dictionary:
my_dict = {'root': '/var/tmp'}
my_dict.update({'file': os.path.join(my_dict.get('root'), 'file')})
Don't use dict
as a name. You may need the real dict
builtin later on.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With