Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #33102

Re: Method default argument whose type is the class not yet defined

Path csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <marco.buttu@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.005
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; 'terry': 0.09; 'def': 0.10; 'subject:not': 0.11; 'received:74.125.82.44': 0.15; '(self': 0.16; '0.0,': 0.16; 'reedy': 0.16; 'self.y': 0.16; 'subject:class': 0.16; 'subject:default': 0.16; 'subject:type': 0.16; 'wrote:': 0.17; 'thanks,': 0.18; 'creates': 0.18; '>>>': 0.18; 'class.': 0.23; 'needed.': 0.23; 'solutions.': 0.23; 'second': 0.24; 'header :In-Reply-To:1': 0.25; 'header:User-Agent:1': 0.26; 'propose': 0.27; 'skip:_ 10': 0.29; 'class': 0.29; 'function': 0.30; 'point': 0.31; 'received:74.125.82': 0.33; 'to:addr:python-list': 0.33; 'received:google.com': 0.34; 'pm,': 0.35; 'message-id:@gmail.com': 0.36; 'received:74.125': 0.36; 'two': 0.37; 'subject:: ': 0.38; 'instead': 0.39; 'to:addr:python.org': 0.39; 'received:192': 0.39; 'received:192.168': 0.40; 'header:Received:5': 0.40; 'first': 0.61; 'distance': 0.62
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=message-id:date:from:user-agent:mime-version:newsgroups:to:subject :references:in-reply-to:content-type:content-transfer-encoding; bh=WgwQovUeXnDDOm5lbD71ZMi+j6BgRsgGfIUyI4qZ05o=; b=bcpRq37DkX9cMY5IgsqoevT1W2A8LL82npAVzPw2qy1EKKk7eKlnzixBW+Jd3Bj8ii 7bOa2OjN5P7w46rc/FM9xq3pgoSEbMgKvkTT0v9zGcVTJMbxAyABqJ+tLFdj0ju0RlLY HI9LAOGapK43joYq712xBnjm5MKDSQ0hyY9hqrX88KESgzjqr/64VWVTkSkep3FyOxLL rTJTH2K3Ype/+LFp3OruiBQ0mJiP7O29S9zcFWyDi3OPrOtYcKrWrSvYRPLfVQlCdmkc ntVCp0fUBM+NJSa1y2tch3vnsslLuii3ib9H7JA8KXdXeK0l2rw8gYt2TEXxvEsuetos C27Q==
Date Sat, 10 Nov 2012 21:51:38 +0100
From Jennie <marco.buttu@gmail.com>
User-Agent Mozilla/5.0 (X11; Linux i686; rv:16.0) Gecko/20121011 Thunderbird/16.0.1
MIME-Version 1.0
Newsgroups comp.lang.python
To python-list@python.org
Subject Re: Method default argument whose type is the class not yet defined
References <k7ma5c$qdk$1@speranza.aioe.org> <mailman.3541.1352579400.27098.python-list@python.org>
In-Reply-To <mailman.3541.1352579400.27098.python-list@python.org>
Content-Type text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding 7bit
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>
Message-ID <mailman.3542.1352580704.27098.python-list@python.org> (permalink)
Lines 31
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1352580704 news.xs4all.nl 6958 [2001:888:2000:d::a6]:43106
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:33102

Show key headers only | View raw


On 11/10/2012 09:29 PM, Terry Reedy wrote:

> On 11/10/2012 2:33 PM, Jennie wrote:
>>
>> I propose three solutions. The first one:
>>
>>  >>> class Point:
>> ...     def __init__(self, x=0, y=0):
>> ...         self.x = x
>> ...         self.y = y
>> ...     def __sub__(self, other):
>> ...         return Point(self.x - other.x, self.y - other.y)
>> ...     def distance(self, point=None):
>> ...         p = point if point else Point()
>> ...         return math.sqrt((self - p).x ** 2 + (self - p).y ** 2)

> What I do not like about this one is that it creates a new 0 point each
> time one is needed. Two solutions:
>
> change Point() to point0 in the distance function and create
> point0 = Point()
> after the class.
>
> -or-
> instead of p = line,
> px,py = point.x, point.y if point else 0.0, 0.0

Thanks, I like the second one :)

-- 
Jennie

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Method default argument whose type is the class not yet defined Jennie <nameDOTportua@gmail.com> - 2012-11-10 20:33 +0100
  Re: Method default argument whose type is the class not yet defined Chris Angelico <rosuav@gmail.com> - 2012-11-11 06:56 +1100
  Re: Method default argument whose type is the class not yet defined Terry Reedy <tjreedy@udel.edu> - 2012-11-10 15:29 -0500
    Re: Method default argument whose type is the class not yet defined Jennie <nameDOTportua@gmail.com> - 2012-11-10 21:51 +0100
      Re: Method default argument whose type is the class not yet defined Dave Angel <d@davea.name> - 2012-11-10 17:30 -0500
    Re: Method default argument whose type is the class not yet defined Jennie <marco.buttu@gmail.com> - 2012-11-10 21:51 +0100
  Re: Method default argument whose type is the class not yet defined Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-11-11 01:13 +0000
    Re: Method default argument whose type is the class not yet defined Chris Angelico <rosuav@gmail.com> - 2012-11-11 13:13 +1100
    Re: Method default argument whose type is the class not yet defined Ian Kelly <ian.g.kelly@gmail.com> - 2012-11-10 19:43 -0700
      Re: Method default argument whose type is the class not yet defined Roy Smith <roy@panix.com> - 2012-11-10 21:53 -0500
        Re: Method default argument whose type is the class not yet defined Ian Kelly <ian.g.kelly@gmail.com> - 2012-11-10 23:43 -0700
        Re: Method default argument whose type is the class not yet defined Ian Kelly <ian.g.kelly@gmail.com> - 2012-11-10 23:45 -0700
    Re: Method default argument whose type is the class not yet defined Chris Angelico <rosuav@gmail.com> - 2012-11-11 13:47 +1100
    Re: Method default argument whose type is the class not yet defined Oscar Benjamin <oscar.j.benjamin@gmail.com> - 2012-11-11 14:21 +0000
      Re: Method default argument whose type is the class not yet defined Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-11-11 22:31 +0000
        Re: Method default argument whose type is the class not yet defined Oscar Benjamin <oscar.j.benjamin@gmail.com> - 2012-11-12 00:31 +0000
          Re: Method default argument whose type is the class not yet defined Steve Howell <showell30@yahoo.com> - 2012-11-11 16:56 -0800
          Re: Method default argument whose type is the class not yet defined Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-11-12 04:46 +0000
        Re: Method default argument whose type is the class not yet defined Mark Lawrence <breamoreboy@yahoo.co.uk> - 2012-11-12 01:10 +0000
          Re: Method default argument whose type is the class not yet defined Roy Smith <roy@panix.com> - 2012-11-11 20:15 -0500
            Re: Method default argument whose type is the class not yet defined Mark Lawrence <breamoreboy@yahoo.co.uk> - 2012-11-12 01:35 +0000
        Re: Method default argument whose type is the class not yet defined Oscar Benjamin <oscar.j.benjamin@gmail.com> - 2012-11-12 01:18 +0000
          Re: Method default argument whose type is the class not yet defined Roy Smith <roy@panix.com> - 2012-11-11 20:34 -0500
        Re: Method default argument whose type is the class not yet defined Mark Lawrence <breamoreboy@yahoo.co.uk> - 2012-11-12 01:29 +0000
        Re: Method default argument whose type is the class not yet defined Oscar Benjamin <oscar.j.benjamin@gmail.com> - 2012-11-12 01:50 +0000
  Re: Method default argument whose type is the class not yet defined Oscar Benjamin <oscar.j.benjamin@gmail.com> - 2012-11-11 01:23 +0000
  Re: Method default argument whose type is the class not yet defined Steve Howell <showell30@yahoo.com> - 2012-11-11 16:32 -0800

csiph-web