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

  • Home
  • SEARCH
  • 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 7090303
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T08:02:01+00:00 2026-05-28T08:02:01+00:00

Assigning a string, integer, and so on with globals() works fine: >>> globals() {‘__builtins__’:

  • 0

Assigning a string, integer, and so on with globals() works fine:

 
>>> globals()
{'__builtins__': , '__name__': '__main__', '__doc__': None, '__package__': None}
>>> globals()["a"] = 5
>>> a
5
>>> globals()
{'__builtins__': , '__name__': '__main__', '__doc__': None, 'a': 5, '__package__': None}

However, trying to assign to a dictionary fails:

>>> globals()["b['c']"] = 5
>>> globals()
{'a': 5, "b['c']": 5, '__builtins__': , '__package__': None, '__name__': '__main__', '__doc__': None}
>>> b['c']
Traceback (most recent call last):
  File "", line 1, in 
NameError: name 'b' is not defined

This is true even if “b” is already defined as a dictionary.

So, given a text string such as “b[‘c’]”, how do I assign b[‘c’]?

  • 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-28T08:02:02+00:00Added an answer on May 28, 2026 at 8:02 am

    I can’t imagine what you’re trying to do here.

    b doesn’t seem to exist in globals already. You can’t assign to a dictionary that doesn’t exist.

    Conceivably, you could do this:

    globals()["b"] = {'c': 5}
    

    which makes b a new dictionary containing one key, c, with a value of 5. But I’d think carefully about why you think you need to modify globals in the first place – there’s almost certainly a better way to do what you want.

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

Sidebar

Related Questions

How do you instantiate an Integer bean, assigning a value, in the Struts 1.x
Valgrind reports a memory leak when assigning a value to a string. I used
Lately I've been in the habit of assigning integer values to constants and simply
How can i convert an integer ranging from 0 to 255 to a string
In my code I'm assigning a String to the name property of a FrameworkElement
Is there any possibility of assigning user agent string to web browser control in
import java.util.*; public class Explorer1 { public static void main(String[] args) { TreeSet<Integer> s
A common problem in LINQ2SQL is while the .NET String allows assigning any length
I am manipulating a large string by removing chunks of characters, and assigning the
i my iphone app while assigning a string value to the table view its

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.