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 6935563
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T12:07:10+00:00 2026-05-27T12:07:10+00:00

i want to know if it is possible to handle variables through a dictionary.

  • 0

i want to know if it is possible to handle variables through a dictionary.

Example:

global MyVar
...
MyVar = 0xFFFF
d={"MyVar":MyVar}
def ChangeVar (var_to_change, value)
 d[var_to_change] = value #I know this code assigns a new value to the key...
...
ChangeVar("MyVar",25)
...

I want to use the dictionary to “select” which variable I will modify. I can always use an array, but I want to know if it is possible to accomplish this. I do not know very much about pointers in Python.

In C would be something like this (maybe I wrote an extra or missed an ‘*’):

int MyCVar = 0;
int MyCVar2 = 0;
int *MyD[] = {&MyCVar,&MyCVar2};
...
*(MyD[index]) = some_value;

I hope you understand what I am trying to explain.

Thank you,

Jonathan

EDIT:
Thank you all for your answers. What I was trying to do was kind of hard since python handles the names and objects quite different. What I did was something like this:

class mytype(object):
   def __init__(self,name=""):
      self.__Name = name
      ....
      myDict[name] = self

then I can access all the objects using the Name of the variable. This is the behavior I tried to explain in the first example. And this is how I would access those objects.

myDict["MyVar"].Value = 1

Thank you all, your answers gave some good ideas.

  • 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-27T12:07:11+00:00Added an answer on May 27, 2026 at 12:07 pm

    In Python there is no sugar to get double-pointer semantics. You need to pass a reference some some object around that can mutate the value you want. For example your dictionary could store a function that had access to MyVar and could change it.

    MyVar = 5
    def ChangeMyVar(value):
        global MyVar
        MyVar = value
    d['MyVar'] = ChangeMyVar
    
    # later..
    d['MyVar'](10)
    

    You’ll be better off designing this to pass around an object that wraps the actual value you care about.

    class WrappedVar(object):
        def __init__(self, val):
            self.value = val
    
    MyVar = WrappedVar(5)
    d['MyVar'] = MyVar
    
    # later..
    d['MyVar'].value = 10
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to know if it is possible to call an activity through background
I know global variables are supposed to be bad but is it possible to
I want to know if its possible and how to do the following ,
Basically, I just want to know if its possible to use Nhibernate to migrate
I want to know if it is possible to end a for loop in
I want to know whether it is possible to commit to a previous version.
I want to know if it's possible to register a type library without using
I want to know if it is possible to stream data from the server
Hey i dont know if that is possible but i want to set a
Is it possible to subclass dynamically? I know there's ____bases____ but I don't want

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.