indirect assignment question

Ben Finney ben+python at benfinney.id.au
Tue May 17 02:01:25 EDT 2011


Andy Baxter <highfellow at gmail.com> writes:

> 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.

for (name, value) in widgetDic.iteritems():
    setattr(self, name, value)

-- 
 \         “The double standard that exempts religious activities from |
  `\       almost all standards of accountability should be dismantled |
_o__)                   once and for all.” —Daniel Dennett, 2010-01-12 |
Ben Finney



More information about the Python-list mailing list