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


Groups > comp.lang.python > #5555

Re: indirect assignment question

From Thomas Rachel <nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915@spamschutz.glglgl.de>
Newsgroups comp.lang.python
Subject Re: indirect assignment question
Date 2011-05-17 09:15 +0200
Organization A newly installed InterNetNews server
Message-ID <iqt7bn$iie$1@r03.glglgl.eu> (permalink)
References <mailman.1657.1305609210.9059.python-list@python.org>

Show all headers | View raw


Am 17.05.2011 07:13 schrieb Andy Baxter:

> 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

assignmap = (
     ('mainWindow', 'window'),
     ('menuitem_output_on', 'outputToggleMenu'),
     ('button_toggle_output', 'outputToggleButton'),
     ('textview_log', 'logView'),
     ('scrolledwindow_log', 'logScrollWindow'),
)
for name, selfname in assignmap:
     val = widgetDic[name] = self.wTree.get_widget(name)
     setattr(self, selfname, val)


HTH,

Thomas

Back to comp.lang.python | Previous | NextPrevious 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