Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #83765
| Path | csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.fsmpi.rwth-aachen.de!newsfeed.straub-nv.de!proxad.net!feeder1-2.proxad.net!news.tele.dk!news.tele.dk!small.news.tele.dk!newsgate.cistron.nl!newsgate.news.xs4all.nl!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.007 |
| X-Spam-Evidence | '*H*': 0.99; '*S*': 0.00; 'explicitly': 0.05; 'method,': 0.09; 'subject:method': 0.09; 'python': 0.11; 'def': 0.12; 'jan': 0.12; '@classmethod': 0.16; 'a(object):': 0.16; 'cleaner': 0.16; 'naming': 0.16; 'subject:class': 0.16; 'wrote:': 0.18; 'wed,': 0.18; 'this:': 0.26; 'header:In-Reply-To:1': 0.27; 'am,': 0.29; 'message-id:@mail.gmail.com': 0.30; "i'm": 0.30; 'too.': 0.31; '3.x': 0.31; 'class': 0.32; 'skip:_ 10': 0.34; 'subject:from': 0.34; 'but': 0.35; 'received:google.com': 0.35; '14,': 0.36; 'curious': 0.36; 'jason': 0.38; 'to:addr:python- list': 0.38; 'to:addr:python.org': 0.39; 'here:': 0.62; '2015': 0.84; '9:45': 0.84 |
| DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type; bh=7rXd/+gQTGDrBAA45dORoN6gniS0u4zVwL0sxCyWmhc=; b=CIC6p+9rpiPWAvka2ekyful8z03JDluoApPDR5Je2S7dCjFKCbCYJVCOWozcUd4AqS tDw1h251yod2RM6Hwux4P6S70nrDVEHWDdB1g7ALJ0xU/EUffAKD1DIOrcDTuQR/pYTW REMfLJKF3wudMeGGbXDGRmuY2p2LF/XFq1RG/yE2Wc4xk1vysvQWDl+5PisTLyq3oqDW u3C1BQxEXjE8VwxUF+GFXesOaqSO70fEGbojdcg2PoCy8ObRhCUm8WEbXl3LYuuabMJy 72AI8Q30v8HCcgnuzkO/yFjO1wSG/td5ZFiBh7QOLIHUtkZEMhRywWjL//ntDr+d0+Yr 6sGA== |
| X-Received | by 10.68.65.112 with SMTP id w16mr7271019pbs.114.1421254851322; Wed, 14 Jan 2015 09:00:51 -0800 (PST) |
| MIME-Version | 1.0 |
| In-Reply-To | <cb109c66-090a-4779-b00e-43d964ae7252@googlegroups.com> |
| References | <cb109c66-090a-4779-b00e-43d964ae7252@googlegroups.com> |
| From | Ian Kelly <ian.g.kelly@gmail.com> |
| Date | Wed, 14 Jan 2015 10:00:11 -0700 |
| Subject | Re: Calling a derived class's constructor from a parent method |
| To | Python <python-list@python.org> |
| Content-Type | text/plain; charset=UTF-8 |
| 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 | <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> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.17727.1421254860.18130.python-list@python.org> (permalink) |
| Lines | 21 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1421254860 news.xs4all.nl 2948 [2001:888:2000:d::a6]:55504 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:83765 |
Show key headers only | View raw
On Wed, Jan 14, 2015 at 9:45 AM, jason <jasonsewall@gmail.com> wrote:
> class A(object):
> def __init__(self, s):
> self.s = s
> def foo(self, s):
> return A(s)
Instead of explicitly naming the return class here, do this:
return self.__class__(s)
Alternatively, since you never use self elsewhere in the method, it
may be cleaner to use a classmethod here:
@classmethod
def foo(cls, s):
return cls(s)
> I'm using Python 2.7.5, but I'm curious what the 3.x answer is too.
The answer is the same in 3.x.
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Calling a derived class's constructor from a parent method jason <jasonsewall@gmail.com> - 2015-01-14 08:45 -0800
Re: Calling a derived class's constructor from a parent method Ian Kelly <ian.g.kelly@gmail.com> - 2015-01-14 10:00 -0700
Re: Calling a derived class's constructor from a parent method Chris Angelico <rosuav@gmail.com> - 2015-01-15 03:56 +1100
Re: Calling a derived class's constructor from a parent method Mark Lawrence <breamoreboy@yahoo.co.uk> - 2015-01-14 17:05 +0000
Re: Calling a derived class's constructor from a parent method jason <jasonsewall@gmail.com> - 2015-01-14 10:10 -0800
Re: Calling a derived class's constructor from a parent method Dave Angel <davea@davea.name> - 2015-01-14 13:41 -0500
Re: Calling a derived class's constructor from a parent method alister <alister.nospam.ware@ntlworld.com> - 2015-01-14 18:18 +0000
Re: Calling a derived class's constructor from a parent method Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2015-01-15 11:40 +1100
Re: Calling a derived class's constructor from a parent method Mark Lawrence <breamoreboy@yahoo.co.uk> - 2015-01-15 04:44 +0000
csiph-web