cdgriffith / Box

Python dictionaries with advanced dot notation access

Home Page:https://github.com/cdgriffith/Box/wiki

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

how to use one more variable inside

ns-ajith opened this issue · comments

Currently, i use

yaml

foo:
  something:
        fishy:
             a: b
             c: d
   test:
              f: h
              h: k

config = Box(hiyapyco.load('config/lambda.yaml', 'config/' + environment + '.yaml', method=hiyapyco.METHOD_MERGE,
                                               interpolate=True, failonmissingfiles=True))

if I do

name = os.getenv(name)   # that is something or test
print (config.name.fishy.a)

How can I use the variable name in the print function?

Sorry if it's a dump question I'm new to python

Box allows you to access things via dot notation, like you show with print (config.name.fishy.a) or still as a normal dictionary like config["test"]["fishy"]["a"]`

In your case you can combine them to use a variable as a key:

print(config[name].fishy.a)

(Appoligies for terse answer / any bad synax, on mobile)

Thank you so much @cdgriffith for the quick help. It worked. yaaaayyy !!