Giving this dictionary:
>>> options = {'DATABASES': {'default': {'ENGINE': 'django.db.backends.sqlite3'}}}
What would be the best way to get this?:
>>> foo(options)
>>> print DATABASES
{'default': {'ENGINE': 'django.db.backends.sqlite3'}}
I am solving this as locals().update(options), but I was thinking, if there is maybe a better solution.
Example:
update 2016-06 A couple of weeks ago I had put together the
extradictPython package – it is available on pypi now. One of its features is theMapGettercontext manager that allows exactly what is being asked forby doing something along:
And other normal “from …. import …. ” usages, but from a dictionary or mapping object (including a default dict).