Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3694550
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T04:30:36+00:00 2026-05-19T04:30:36+00:00

Giving this dictionary: >>> options = {‘DATABASES’: {‘default’: {‘ENGINE’: ‘django.db.backends.sqlite3’}}} What would be the

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T04:30:37+00:00Added an answer on May 19, 2026 at 4:30 am
    import inspect
    
    allowed_vars = set(["min_", "max_", "path", ...])
    def update_globals(dic):
        caller_frame = inspect.currentframe(1)
        globals = caller_frame.f_globals
        # here, you _could_ simply do globals.update(dic) 
        # but it is  evil
        for key, value in dic.items():
            #here you should carefully verify each key, and value for not
            #not dangerous pairs, with stuff like:
            #if key not in allowed_vars:
            #    sys.stderr.write("Warning: invalid variable in configuration update\n")
            #     continue
            #if type(value) not in (string, int, float):
            #    #(issue error)
            #    continue
            globals[key] = value
    

    Example:

    >>> a
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    NameError: name 'a' is not defined
    >>> update_globals({"a": 5})
    >>> a
    5
    

    update 2016-06 A couple of weeks ago I had put together the extradict Python package – it is available on pypi now. One of its features is the MapGetter context manager that allows exactly what is being asked for
    by doing something along:

    from extradict import MapGetter
    
    def myfunc():
        options = {'DATABASES': {'default': {'ENGINE': 'django.db.backends.sqlite3'}}}
        with MapGetter(options) as options:
             from options import DATABASES
     ...
    

    And other normal “from …. import …. ” usages, but from a dictionary or mapping object (including a default dict).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When I run player.php it's giving this error: Warning: Cannot modify header information -
I can't figure this out. Capistrano keeps giving me this error: ** [out ::
This snippet of Perl code in my program is giving the wrong result. $condition
Oracle is giving me an error (ORA-00907: missing right parenthesis) when I run this
While I understand this question is fairly vague since I'm not giving you all
This is using the web app framework, not Django. The following template code is
Calling Index view is giving me this very very annoying error . Can anybody
I'm having this annoyning problem giving this message in the console: Failed to launch
This line of code: [mymutabledict setObject:myclassobj forKey:myclassobj.myidstring]; Is giving this error: *** -[NSCFString hash]:
this is my code NSDictionary *dictionary = [self.tableDataSource objectAtIndex:indexPath.row]; NSArray *Children = [dictionary objectForKey:@Children];

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.