Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #5550
| Path | csiph.com!x330-a1.tempe.blueboxinc.net!feeder1.hal-mli.net!weretis.net!feeder1.news.weretis.net!feeder.erje.net!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <chris@rebertia.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.004 |
| X-Spam-Evidence | '*H*': 0.99; '*S*': 0.00; 'assign': 0.05; 'dictionary': 0.07; 'python?': 0.07; 'python': 0.07; 'referenced': 0.09; 'pm,': 0.11; 'this:': 0.11; 'wrote:': 0.14; 'baxter': 0.16; 'indirect': 0.16; '16,': 0.16; 'cc:no real name:2**0': 0.20; 'cc:2**0': 0.20; 'cheers,': 0.20; 'variable': 0.21; 'code': 0.22; 'header:In-Reply-To:1': 0.22; 'subject:question': 0.22; 'cc:addr :python-list': 0.22; 'mon,': 0.22; 'received:209.85.213': 0.23; 'similarly': 0.23; 'somehow': 0.23; 'value.': 0.25; 'chris': 0.27; 'message-id:@mail.gmail.com': 0.28; 'hi,': 0.29; 'cc:addr:python.org': 0.31; 'andy': 0.31; 'skip:\xc2 20': 0.31; '...': 0.32; '(for': 0.33; 'lines': 0.34; 'using': 0.34; 'skip:" 10': 0.34; 'there': 0.35; 'point': 0.35; 'assignment': 0.35; 'doing': 0.36; 'some': 0.37; 'refer': 0.37; 'received:209.85': 0.37; 'received:google.com': 0.38; 'less': 0.38; 'skip:" 20': 0.38; 'set': 0.39; 'skip:s 30': 0.39; 'where': 0.39; 'received:209': 0.39; '8bit%:8': 0.39; 'would': 0.40; 'header:Received:5': 0.40; '8bit%:9': 0.60; '8bit%:14': 0.60; 'choose': 0.61; '2011': 0.62; 'skip:\xc2 10': 0.83 |
| DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=rebertia.com; s=google; h=domainkey-signature:mime-version:sender:in-reply-to:references:date :x-google-sender-auth:message-id:subject:from:to:cc:content-type :content-transfer-encoding; bh=AStqlWAglUfKmlxBDgk3Mw6T6ZHsVz1AD8QSNjJG+D8=; b=MAnPYYCP+uU300zszZn2GrvqWtYNaRnfCTQxSuYGrIfMgKR8Xj9UmHMvXHk1fMly2X SR0OFhg39rSZM9M46aE78j9WNc+NHefho44VuYMBy0+wiSapnQuOdDsxYAAyZo9S681h NtMYkk6B3ybnc3lImkYwQ9jVfNuGfUd9YeCEQ= |
| DomainKey-Signature | a=rsa-sha1; c=nofws; d=rebertia.com; s=google; h=mime-version:sender:in-reply-to:references:date :x-google-sender-auth:message-id:subject:from:to:cc:content-type :content-transfer-encoding; b=fn1JzCVix5doGrAe+oQ4hV1V/j9yFAmepy0lM0/pOrsS5X+5BYyY3QIPqF2s9rk4t5 XusMYKr9o/nszeF3Q+8iy0CoprXBFwpNCZboGU7Tc3fl1CZGmB7TkQRE8qxqHsfxc8lm dh1V7f/pxvwqQJtsQPkqm1HQTnsKQ2Y0VKUh4= |
| MIME-Version | 1.0 |
| Sender | chris@rebertia.com |
| In-Reply-To | <4DD203F1.1000202@gmail.com> |
| References | <4DD203F1.1000202@gmail.com> |
| Date | Mon, 16 May 2011 22:24:34 -0700 |
| X-Google-Sender-Auth | lBk57TgicJqy9Ed5shXkeU6Klxg |
| Subject | Re: indirect assignment question |
| From | Chris Rebert <clp2@rebertia.com> |
| To | Andy Baxter <highfellow@gmail.com> |
| Content-Type | text/plain; charset=UTF-8 |
| Content-Transfer-Encoding | quoted-printable |
| Cc | python-list@python.org |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.12 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.1658.1305609877.9059.python-list@python.org> (permalink) |
| Lines | 55 |
| NNTP-Posting-Host | 82.94.164.166 |
| X-Trace | 1305609877 news.xs4all.nl 49174 [::ffff:82.94.164.166]:36918 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | x330-a1.tempe.blueboxinc.net comp.lang.python:5550 |
Show key headers only | View raw
On Mon, May 16, 2011 at 10:13 PM, Andy Baxter <highfellow@gmail.com> wrote:
> 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?
You can achieve almost the same level of brevity, with less use of
magic, by simply using a local variable to refer to
self.wTree.get_widget:
w = self.wTree.get_widget # or choose some other similarly short variable name
self.window = w("mainWindow")
self.outputToggleMenu = w("menuitem_output_on")
self.outputToggleButton = w("button_toggle_output")
self.logView = w("textview_log")
self.logScrollWindow = w("scrolledwindow_log")
Python functions/methods are first-class; exploit this feature!
Cheers,
Chris
--
http://rebertia.com
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: indirect assignment question Chris Rebert <clp2@rebertia.com> - 2011-05-16 22:24 -0700
csiph-web