Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!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.006 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'expressions': 0.07; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'assignments.': 0.16; 'message-id:@post.gmane.org': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'skip:[ 30': 0.16; 'skip:f 30': 0.19; 'header:User-Agent:1': 0.23; 'header:X-Complaints- To:1': 0.27; "d'aprano": 0.31; 'received:132': 0.31; 'steven': 0.31; 'writes:': 0.31; 'another': 0.32; 'skip:d 20': 0.34; "can't": 0.35; 'charset:us-ascii': 0.36; 'to:addr:python-list': 0.38; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'skip:o 30': 0.61; 'temporary': 0.65 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Wolfgang Maier Subject: Re: Method chaining Date: Fri, 22 Nov 2013 16:52:51 +0000 (UTC) References: <528f3f4e$0$29992$c3e8da3$5496439d@news.astraweb.com> <528f6989$0$29992$c3e8da3$5496439d@news.astraweb.com> <528f859e$0$29992$c3e8da3$5496439d@news.astraweb.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: sea.gmane.org User-Agent: Loom/3.14 (http://gmane.org/) X-Loom-IP: 132.230.235.10 (Mozilla/5.0 (Windows NT 6.1; rv:25.0) Gecko/20100101 Firefox/25.0) 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: , Newsgroups: comp.lang.python Message-ID: Lines: 37 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1385139196 news.xs4all.nl 15940 [2001:888:2000:d::a6]:41889 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:60243 Steven D'Aprano pearwood.info> writes: > # With chaining > thing = func(MyClass().spam().eggs().cheese(), > MyClass().aardvark(), > OtherClass().fe().fi().fo().fum(), > ) > do_stuff_with(thing) > > versus: > > # Without chaining > temp1 = MyClass() > temp1.spam() > temp1.eggs() > temp1.cheese() > temp2 = MyClass() > temp2.aardvark() > temp3 = OtherClass() > temp3.fe() > temp3.fi() > temp3.fo() > temp3.fum() > thing = func(temp1, temp2, temp3) > do_stuff_with(thing) > Another use case might be in comprehensions and generator expressions ?? thing = [MyClass().spam().eggs(x).cheese() for x in sequence] where you can't use all those temporary assignments. Best, Wolfgang