Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #5549

indirect assignment question

Date 2011-05-17 06:13 +0100
From Andy Baxter <highfellow@gmail.com>
Subject indirect assignment question
Newsgroups comp.lang.python
Message-ID <mailman.1657.1305609210.9059.python-list@python.org> (permalink)

Show all headers | View raw


Hi,

I have some lines of code which currently look like this:

       self.window = self.wTree.get_widget("mainWindow")
       self.outputToggleMenu = self.wTree.get_widget("menuitem_output_on")
       self.outputToggleButton = 
self.wTree.get_widget("button_toggle_output")
       self.logView = self.wTree.get_widget("textview_log")
       self.logScrollWindow = self.wTree.get_widget("scrolledwindow_log")

and I would like (for tidiness / compactness's sake) to replace them 
with something like this:
         widgetDic = {
            "mainWindow": self.window,
            "menuitem_output_on": self.outputToggleMenu,
            "button_toggle_output": self.outputToggleButton,
            "textview_log": self.logView,
            "scrolledwindow_log": self.logScrollWindow
         }
         for key in widgetDic:
            ... set the variable in dic[key] to point to 
self.wTree.get_widget(key) somehow

what I need is some kind of indirect assignment where I can assign to a 
variable whose name is referenced in a dictionary value.

Is there a way of doing this in python?

thanks,

andy baxter

-- 

http://highfellow.org

Back to comp.lang.python | Previous | NextNext in thread | Find similar | Unroll thread


Thread

indirect assignment question Andy Baxter <highfellow@gmail.com> - 2011-05-17 06:13 +0100
  Re: indirect assignment question Ben Finney <ben+python@benfinney.id.au> - 2011-05-17 16:01 +1000
  Re: indirect assignment question Thomas Rachel <nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915@spamschutz.glglgl.de> - 2011-05-17 09:15 +0200

csiph-web