Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #19693
| Path | csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!newsfeed.eweka.nl!feeder3.eweka.nl!81.171.88.15.MISMATCH!eweka.nl!lightspeed.eweka.nl!194.134.4.91.MISMATCH!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <arnodel@gmail.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.018 |
| X-Spam-Evidence | '*H*': 0.96; '*S*': 0.00; 'attributes': 0.05; 'def': 0.13; 'received:209.85.214.174': 0.13; "subject:' ": 0.15; 'cc:addr:python-list': 0.15; 'subject:named': 0.16; 'thing?': 0.16; 'tuple,': 0.16; 'wrote:': 0.16; 'trying': 0.20; 'cc:no real name:2**0': 0.21; "doesn't": 0.22; 'header:In-Reply-To:1': 0.22; 'assigning': 0.23; 'index': 0.24; 'cc:2**0': 0.25; 'skip:_ 20': 0.26; 'message-id:@mail.gmail.com': 0.28; 'cc:addr:python.org': 0.29; 'class': 0.29; 'value)': 0.30; 'received:209.85.214': 0.32; 'named': 0.33; 'object': 0.33; 'there': 0.33; 'but': 0.37; 'received:google.com': 0.37; 'using': 0.37; 'skip:_ 10': 0.37; 'received:209.85': 0.38; 'received:209': 0.39; 'custom': 0.61; 'skip:\xc2 10': 0.74; 'emmanuel': 0.84; 'methods)': 0.84 |
| DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type:content-transfer-encoding; bh=keyqoGUb5FZn44tWKSH9AVRsA5RshcTGOskatvyXrNA=; b=GT2nYVtgl6TkeAaGOAq+dlHvHbqmt28lNToQ9eqWJfXAn6CZ7pn1t+OIRap+kCHBRs ShdFezAFHV3XZRh4SoRquJA62koxFCeAKH5l06MsBQdjKlBimmACCI54N7wp1Mgae9vR b8NdQ+Wbo60YZooN4bKu0Ph2xgOUWiUN4Se5A= |
| MIME-Version | 1.0 |
| In-Reply-To | <CACB6ZmC0JV6bY_t96KUggChb0F=pKArWKg4+hGc5Q9i1KvsO=Q@mail.gmail.com> |
| References | <CACB6ZmC0JV6bY_t96KUggChb0F=pKArWKg4+hGc5Q9i1KvsO=Q@mail.gmail.com> |
| Date | Wed, 1 Feb 2012 07:17:10 +0000 |
| Subject | Re: 'class' named tuple |
| From | Arnaud Delobelle <arnodel@gmail.com> |
| To | Emmanuel Mayssat <emayssat@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.5289.1328080633.27778.python-list@python.org> (permalink) |
| Lines | 23 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1328080633 news.xs4all.nl 6860 [2001:888:2000:d::a6]:56715 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | x330-a1.tempe.blueboxinc.net comp.lang.python:19693 |
Show key headers only | View raw
On 1 February 2012 00:54, Emmanuel Mayssat <emayssat@gmail.com> wrote:
> I have the following program.
> I am trying to have index the attributes of an object using __getitem__.
> Reading them this way works great, but assigning them a value doesn't
> Is there a way to do such a thing?
> (Almost like a named tuple, but with custom methods)
>
> class LIter(object):
> def __init__(self,parent=None):
> super(LIter, self).__init__()
> self.toto = 3
> self.tata = 'terto'
>
Add
_attrs = 'toto', 'tata'
def __getitem__(self, index):
return getattr(self, _attrs[index])
def __setitem__(self, index, value)
setattr(self, _attrs[index], value)
--
Arnaud
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: 'class' named tuple Arnaud Delobelle <arnodel@gmail.com> - 2012-02-01 07:17 +0000
csiph-web