Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #40341
| Path | csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <ian.g.kelly@gmail.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.003 |
| X-Spam-Evidence | '*H*': 0.99; '*S*': 0.00; 'args': 0.04; 'method.': 0.05; 'modified': 0.05; 'args)': 0.07; 'testing,': 0.07; '*args):': 0.09; '__init__': 0.09; 'overridden': 0.09; 'def': 0.10; 'sat,': 0.15; '__new__': 0.16; 'inheritance': 0.16; 'initializes': 0.16; 'need:': 0.16; 'wrote:': 0.17; 'pass': 0.25; 'header:In-Reply-To:1': 0.25; 'am,': 0.27; 'message- id:@mail.gmail.com': 0.27; "doesn't": 0.28; 'subject:list': 0.28; 'included': 0.29; 'skip:_ 10': 0.29; 'class': 0.29; 'that.': 0.30; 'to:addr:python-list': 0.33; 'received:google.com': 0.34; 'list': 0.35; 'subject:?': 0.35; 'received:209.85': 0.35; 'method': 0.36; 'received:209': 0.37; 'subject:: ': 0.38; 'to:addr:python.org': 0.39; 'further': 0.61; 'here': 0.65; 'want,': 0.65; 'receive': 0.71; 'subject:this': 0.84; '2013': 0.84; 'contents,': 0.84; 'to:name:python': 0.84 |
| DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=x-received:mime-version:in-reply-to:references:from:date:message-id :subject:to:content-type; bh=Hyy1KgLHFzX9Sl+cLL+2zDjzWPyVTrCWCoq5L8Cn5eI=; b=ojcdyfuTWRfo3FWPrQSUtgqfLHxodhwMtssLwsqZDnqKgiR/b/i37kh4pSJJXekUnf D8O0yxU+Y9ky+REGj4vBzDYoCnDJb8aJX3z4gkoRD1U30NGXHmJOmUrKcBmaqx0q2jBP lRSYl6iJjhFgyqhPi5Gy4OdBFSY1ljomuUDYq3wJsdrISQEKbZlVbFuG6TbInJUJM+s5 PNgoFpaaCQjcB2JLRXBf9bNJywRd428jBwNkELMi9Pb/Tg+Ol4M7HIXwDioANaMdo9sc nGnSz2t0G0q8XfYqmLqVaTH4voch0xr/2A3p79pyLJ03aYhD+xWsYGJjG79cnsb9Lkyr zarA== |
| X-Received | by 10.52.177.163 with SMTP id cr3mr4905565vdc.94.1362245244258; Sat, 02 Mar 2013 09:27:24 -0800 (PST) |
| MIME-Version | 1.0 |
| In-Reply-To | <CALwzidm+TDHXRZwxHWo+Qbozw7SZJzqyX2KHGBF9Pgv+ytChUw@mail.gmail.com> |
| References | <kgtbb9$3ps$1@tdi.cu.mi.it> <CALwzidm+TDHXRZwxHWo+Qbozw7SZJzqyX2KHGBF9Pgv+ytChUw@mail.gmail.com> |
| From | Ian Kelly <ian.g.kelly@gmail.com> |
| Date | Sat, 2 Mar 2013 10:26:44 -0700 |
| Subject | Re: Is it correct this way to inherit from a list? |
| To | Python <python-list@python.org> |
| Content-Type | text/plain; charset=ISO-8859-1 |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.15 |
| 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.2781.1362245252.2939.python-list@python.org> (permalink) |
| Lines | 21 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1362245252 news.xs4all.nl 6876 [2001:888:2000:d::a6]:53488 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:40341 |
Show key headers only | View raw
On Sat, Mar 2, 2013 at 10:22 AM, Ian Kelly <ian.g.kelly@gmail.com> wrote:
> class Vector(list):
> def __new__(cls, *args):
> return super(Vector, cls).__new__(cls, args)
> def __init__(self, *args):
> super(Vector, self).__init__(args)
>
> The __new__ method here will receive the args in the style that you
> want, and then pass them up the inheritance chain to the superclass
> constructor, which will then just do the right thing. The __init__
> method is also overridden to match the modified argspec. The
> super().__init__() call is included for completeness; AFAIK it doesn't
> actually do anything.
I retract that. On further testing, it is actually the __init__
method that initializes the list contents, not the __new__ method. So
this is all you need:
class Vector(list):
def __init__(self, *args):
super(Vector, self).__init__(args)
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Is it correct this way to inherit from a list? gialloporpora <gialloporpora@gmail.com> - 2013-03-02 18:02 +0100
Re: Is it correct this way to inherit from a list? Peter Otten <__peter__@web.de> - 2013-03-02 18:19 +0100
Re: Is it correct this way to inherit from a list? Ian Kelly <ian.g.kelly@gmail.com> - 2013-03-02 10:22 -0700
Re: Is it correct this way to inherit from a list? Ian Kelly <ian.g.kelly@gmail.com> - 2013-03-02 10:26 -0700
Re: Is it correct this way to inherit from a list? gialloporpora <gialloporpora@gmail.com> - 2013-03-03 03:33 +0100
Re: Is it correct this way to inherit from a list? Rick Johnson <rantingrickjohnson@gmail.com> - 2013-03-02 09:46 -0800
Re: Is it correct this way to inherit from a list? gialloporpora <gialloporpora@gmail.com> - 2013-03-03 03:30 +0100
Re: Is it correct this way to inherit from a list? Chris Angelico <rosuav@gmail.com> - 2013-03-03 14:18 +1100
Re: Is it correct this way to inherit from a list? "Colin J. Williams" <cjw@ncf.ca> - 2013-03-03 09:21 -0500
Re: Is it correct this way to inherit from a list? Jason Swails <jason.swails@gmail.com> - 2013-03-03 15:40 -0500
csiph-web