Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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')
}
like image 386
AK47 Avatar asked Jul 07 '16 20:07

AK47


1 Answers

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.

like image 115
Moses Koledoye Avatar answered Oct 16 '22 06:10

Moses Koledoye