Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #84514
| 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!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed1a.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <rosuav@gmail.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.028 |
| X-Spam-Evidence | '*H*': 0.94; '*S*': 0.00; 'subject:Python': 0.06; 'method,': 0.09; 'cc:addr:python-list': 0.11; 'def': 0.12; 'jan': 0.12; 'fine.': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'y):': 0.16; 'fix': 0.17; 'wrote:': 0.18; 'have:': 0.19; 'cc:addr:python.org': 0.22; 'fraction': 0.24; 'instead.': 0.24; 'cc:2**0': 0.24; 'class.': 0.26; 'header:In- Reply-To:1': 0.27; 'am,': 0.29; "doesn't": 0.30; 'message- id:@mail.gmail.com': 0.30; '25,': 0.31; "they'll": 0.31; 'class': 0.32; 'brian': 0.33; 'skip:_ 10': 0.34; 'operations': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'should': 0.36; 'skip:- 20': 0.37; 'clear': 0.37; 'that,': 0.38; 'how': 0.40; 'ensure': 0.60; 'easy': 0.60; 'new': 0.61; 'more': 0.64; 'delegate': 0.68; '2015': 0.84; 'sorry.': 0.91; 'to:none': 0.92 |
| DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:cc :content-type; bh=LnXBg4Q49Kknrm0FwyQkFETT75RAjSHvX/85ZHA8swk=; b=nsO0PMud9KCwnwR7V4DzJ3UjHy2yKC0c1qDxHspvx46ZPwyWjxck2lEEoeDLLjv3ZM K6eZytaQda4hbskb8KzsmHVliBLpiL5olDh6wRnmPJYt1R6Hhg6kusBMheHp4UiXHr/S 3cUh3yqTneCkSbixfkH9XtZZV/aeubnJ6DOU3HGxdOwZTiI0XjBHEDNkKNT7b7uHkoqJ Kk/sviYHJERRI506LleAft9hIhgGZA5b/6+7ZkMYIbAa4drk82vqXLFZaMtlhMcWHNm0 yhXX3MiYbYVbqwshHVWBJBxVpwwJD4rz5hs6nkH5FNHo1EMNcYwWPCPY4FhUpZhqF6PZ cpzQ== |
| MIME-Version | 1.0 |
| X-Received | by 10.140.109.55 with SMTP id k52mr26520899qgf.99.1422141730297; Sat, 24 Jan 2015 15:22:10 -0800 (PST) |
| In-Reply-To | <FeCdnXdsTpunvlnJnZ2dnUVZ8judnZ2d@brightview.co.uk> |
| References | <FeCdnXdsTpunvlnJnZ2dnUVZ8judnZ2d@brightview.co.uk> |
| Date | Sun, 25 Jan 2015 10:22:10 +1100 |
| Subject | Re: Delegation in Python |
| From | Chris Angelico <rosuav@gmail.com> |
| Cc | "python-list@python.org" <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.18106.1422141738.18130.python-list@python.org> (permalink) |
| Lines | 27 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1422141738 news.xs4all.nl 2924 [2001:888:2000:d::a6]:53431 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:84514 |
Show key headers only | View raw
On Sun, Jan 25, 2015 at 9:57 AM, Brian Gladman <noone@nowhere.net> wrote:
> But I am not clear on how to delegate from my new class to the existing
> Fraction class. This is what I have:
>
> --------------------------
> class RF(Fraction):
>
> def __new__(self, x, y):
> super().__new__(self, x, y)
>
> def is_integer(self):
> return self.numerator % self.denominator == 0
>
> def __getattr__(self, attr):
> return getattr(self, attr)
If you just drop everything but your new method, it should work just fine.
class RF(Fraction):
def is_integer(self):
return self.numerator % self.denominator == 0
However, this doesn't ensure that operations on RFs will return more
RFs - they'll often return Fractions instead. There's no easy fix for
that, sorry.
ChrisA
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Delegation in Python Brian Gladman <noone@nowhere.net> - 2015-01-24 22:57 +0000
Re: Delegation in Python Chris Angelico <rosuav@gmail.com> - 2015-01-25 10:22 +1100
Re: Delegation in Python Brian Gladman <noone@nowhere.net> - 2015-01-24 23:38 +0000
Re: Delegation in Python Chris Angelico <rosuav@gmail.com> - 2015-01-25 10:43 +1100
Re: Delegation in Python Brian Gladman <noone@nowhere.net> - 2015-01-25 00:18 +0000
Re: Delegation in Python Chris Angelico <rosuav@gmail.com> - 2015-01-25 11:28 +1100
Re: Delegation in Python Brian Gladman <noone@nowhere.net> - 2015-01-25 07:49 +0000
Re: Delegation in Python Chris Angelico <rosuav@gmail.com> - 2015-01-25 19:07 +1100
Re: Delegation in Python Gary Herron <gherron@digipen.edu> - 2015-01-24 15:47 -0800
Re: Delegation in Python Brian Gladman <noone@nowhere.net> - 2015-01-24 23:58 +0000
Re: Delegation in Python Gary Herron <gherron@digipen.edu> - 2015-01-24 15:41 -0800
Re: Delegation in Python Brian Gladman <noone@nowhere.net> - 2015-01-24 23:52 +0000
Re: Delegation in Python Mark Lawrence <breamoreboy@yahoo.co.uk> - 2015-01-24 23:59 +0000
Re: Delegation in Python Chris Angelico <rosuav@gmail.com> - 2015-01-25 11:07 +1100
Re: Delegation in Python Terry Reedy <tjreedy@udel.edu> - 2015-01-24 20:31 -0500
Re: Delegation in Python Brian Gladman <noone@nowhere.net> - 2015-01-25 07:43 +0000
csiph-web