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: 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 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: In-Reply-To: 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Message-ID: 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 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