As goldmab noted, modifying the output of locals() inside a function won't work:
SyntaxError: invalid syntax
>>> def foo():
... locals().update({'a': 1})
... print a
...
>>> foo()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<stdin>", line 3, in foo
NameError: global name 'a' is not defined
This isn't really a very clean way either, but it would do the job:
>>> def foo():
... options = {'DATABASES': {'default': {'ENGINE': 'django.db.backends.sqlite3'}}}
... for k, v in options.items():
... exec('%s = v' % k)
... print DATABASES
...
>>> foo()
{'default': {'ENGINE': 'django.db.backends.sqlite3'}}
Note, by the way, that each key in your dict would need to be ok as a variable. So for example, if the dictionary contained 'DATABASE-USERNAME' as a key, trying to assign that to a variable would cause an exception. Further, doing this would make you vulnerable to code injection attacks if you get the options dictionary from an untrustworthy source. (A key could say something like, "import os ; os.system('sudo adduser scriptkiddie') ; ..."