Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #109988
| Path | csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail |
|---|---|
| From | Random832 <random832@fastmail.com> |
| Newsgroups | comp.lang.python |
| Subject | Re: Bulk Adding Methods Pythonically |
| Date | Wed, 15 Jun 2016 14:21:57 -0400 |
| Lines | 20 |
| Message-ID | <mailman.80.1466014920.2288.python-list@python.org> (permalink) |
| References | <njs3nv$b19$1@dont-email.me> <1466014917.388175.638768225.2DAFD4E9@webmail.messagingengine.com> |
| Mime-Version | 1.0 |
| Content-Type | text/plain |
| Content-Transfer-Encoding | 7bit |
| X-Trace | news.uni-berlin.de EaveWQ5kWohlfvnLehti+QeHhmiVJvZHLnLnmrb3UpHQ== |
| Return-Path | <random832@fastmail.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.002 |
| X-Spam-Evidence | '*H*': 1.00; '*S*': 0.00; 'line:': 0.07; 'answer?': 0.09; 'received:internal': 0.09; 'def': 0.13; 'wed,': 0.15; '[it': 0.16; 'cleaner': 0.16; 'message-id:@webmail.messagingengine.com': 0.16; 'received:10.202': 0.16; 'received:10.202.2': 0.16; 'received:66.111': 0.16; 'received:66.111.4': 0.16; 'received:66.111.4.27': 0.16; 'received:io': 0.16; 'received:messagingengine.com': 0.16; 'received:out3-smtp.messagingengine.com': 0.16; 'received:psf.io': 0.16; 'subject:Adding': 0.16; 'wrote:': 0.16; 'class,': 0.22; 'nearly': 0.23; 'header:In-Reply-To:1': 0.24; "i've": 0.25; 'define': 0.27; 'actual': 0.28; 'dictionary': 0.29; 'loop,': 0.29; 'code': 0.30; '15,': 0.30; 'anyone': 0.32; 'class': 0.33; 'channel': 0.34; 'definition': 0.34; 'add': 0.34; 'but': 0.36; 'instead': 0.36; 'to:addr:python-list': 0.36; 'subject:: ': 0.37; 'received:10': 0.37; 'being': 0.37; 'missing': 0.37; 'things': 0.38; 'detail': 0.38; 'received:66': 0.38; 'why': 0.39; 'to:addr:python.org': 0.40; 'some': 0.40; 'header:Message-Id:1': 0.61; 'frequency': 0.66 |
| DKIM-Signature | v=1; a=rsa-sha1; c=relaxed/relaxed; d=fastmail.com; h= content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-sasl-enc :x-sasl-enc; s=mesmtp; bh=5geSDFi8R6smDg/wEok5P93jaB0=; b=HHIopR 0uVo/xRfuVO51obgoUSOLWv02KlR6QmbCgf0QyOQ0TEW1WEQYqpDpkv8Ti45jFNk uTj6Vl5B5Cx7hPa0vup7lVX+iKO4iTPZNH6tRWuuJ3Yv5qv4oQTlfhQ0ashdkMwf RppPT+F+xXMOMjqmHJjPZ2cQypXYf1coSxLhg= |
| DKIM-Signature | v=1; a=rsa-sha1; c=relaxed/relaxed; d= messagingengine.com; h=content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-sasl-enc:x-sasl-enc; s=smtpout; bh=5geSDFi8R6smDg/ wEok5P93jaB0=; b=L7n9eVX7aWEmJcRgBhxTz/9tZRDf0Bf6XqVKfePATLhRAZB ZnSk1Z2SyMFxK2Q28GSmMlXY7PUkqVBf50jIt3LPDkAC7agOGGwuh4x/SkIS4fdq eGgiGpp88X+CH3h1AE7SKqOGbREAMZxmLB0dHTVj86EuUuoa+FN+i395f8KU= |
| X-Sasl-Enc | m0wF2eTrXcyD9yp70sIjAhdm15iAo5faxnHkUViOen+M 1466014917 |
| X-Mailer | MessagingEngine.com Webmail Interface - ajax-aff28cd1 |
| In-Reply-To | <njs3nv$b19$1@dont-email.me> |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.22 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <https://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 | <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| X-Mailman-Original-Message-ID | <1466014917.388175.638768225.2DAFD4E9@webmail.messagingengine.com> |
| X-Mailman-Original-References | <njs3nv$b19$1@dont-email.me> |
| Xref | csiph.com comp.lang.python:109988 |
Show key headers only | View raw
On Wed, Jun 15, 2016, at 13:37, Rob Gaddi wrote:
> I've got a whole lot of methods I want to add to my Channel class, all
> of which following nearly the same form. The below code works, but
> having to do the for loop outside of the main class definition feels
> kludgey. Am I missing some cleaner answer?
Inside the class definition you can add things to locals() [it returns
the actual dictionary being used in class preparation], but I don't know
if this can be relied on or is an implementation detail of CPython.
Anyone know?
But anyway, instead of using a loop, why not just define each one on its
own line:
def mkmeasure(fnname, measparam):
...
class Channel:
frequency = mkmeasure('frequency', 'FREQ')
falltime = mkmeasure('falltime', 'FTIM')
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Bulk Adding Methods Pythonically Rob Gaddi <rgaddi@highlandtechnology.invalid> - 2016-06-15 17:37 +0000
Re: Bulk Adding Methods Pythonically Random832 <random832@fastmail.com> - 2016-06-15 14:21 -0400
Re: Bulk Adding Methods Pythonically Rob Gaddi <rgaddi@highlandtechnology.invalid> - 2016-06-15 18:39 +0000
Re: Bulk Adding Methods Pythonically Steven D'Aprano <steve@pearwood.info> - 2016-06-16 11:38 +1000
Re: Bulk Adding Methods Pythonically Rob Gaddi <rgaddi@highlandtechnology.invalid> - 2016-06-21 17:04 +0000
Re: Bulk Adding Methods Pythonically Ethan Furman <ethan@stoneleaf.us> - 2016-06-15 12:03 -0700
Re: Bulk Adding Methods Pythonically lists@juliensalort.org (Julien Salort) - 2016-06-16 17:53 +0200
Re: Bulk Adding Methods Pythonically Steven D'Aprano <steve@pearwood.info> - 2016-06-17 03:36 +1000
Re: Bulk Adding Methods Pythonically Lawrence D’Oliveiro <lawrencedo99@gmail.com> - 2016-06-15 18:59 -0700
Re: Bulk Adding Methods Pythonically Random832 <random832@fastmail.com> - 2016-06-16 12:15 -0400
Re: Bulk Adding Methods Pythonically Ethan Furman <ethan@stoneleaf.us> - 2016-06-16 12:58 -0700
csiph-web