Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.013 X-Spam-Evidence: '*H*': 0.97; '*S*': 0.00; 'operator': 0.03; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'subject:module': 0.09; 'unittest': 0.09; '2.7': 0.14; 'lambda': 0.16; 'obj1': 0.16; 'obj2': 0.16; 'readability': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'wrote:': 0.18; 'wed,': 0.18; 'module': 0.19; '>>>': 0.22; 'header :User-Agent:1': 0.23; "aren't": 0.24; 'received:comcast.net': 0.24; 'header:X-Complaints-To:1': 0.27; 'header:In-Reply-To:1': 0.27; 'point': 0.28; "i'm": 0.30; '>>>>': 0.31; 'convenience': 0.31; 'opposed': 0.36; 'to:addr:python-list': 0.38; 'pm,': 0.38; 'sure': 0.39; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'simply': 0.61; 'back': 0.62; 'situation': 0.65; 'therefore': 0.72; '2014,': 0.84; 'ethan': 0.84; 'furman': 0.84; 'lol,': 0.84; 'mind:': 0.84; 'springs': 0.84; 'do:': 0.91 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Ned Batchelder Subject: Re: operator module functions Date: Wed, 08 Oct 2014 21:41:12 -0400 References: <54349662$0$12987$c3e8da3$5496439d@news.astraweb.com> <543518a5$0$12989$c3e8da3$5496439d@news.astraweb.com> <543592AE.80807@stoneleaf.us> <1412797764.3704154.176743089.32D63D13@webmail.messagingengine.com> <54359623.8060307@stoneleaf.us> <1412803417.3733140.176776081.0B98584A@webmail.messagingengine.com> <5435B14C.9020907@stoneleaf.us> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: c-50-133-228-126.hsd1.ma.comcast.net User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:24.0) Gecko/20100101 Thunderbird/24.6.0 In-Reply-To: <5435B14C.9020907@stoneleaf.us> 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: 35 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1412818884 news.xs4all.nl 2831 [2001:888:2000:d::a6]:49853 X-Complaints-To: abuse@xs4all.nl Path: csiph.com!usenet.pasdenom.info!bete-des-vosges.org!feed.ac-versailles.fr!nerim.net!novso.com!newsfeed.xs4all.nl!newsfeed2a.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Xref: csiph.com comp.lang.python:78867 On 10/8/14 5:49 PM, Ethan Furman wrote: > [redirecting back to the list] > > On 10/08/2014 02:23 PM, random832@fastmail.us wrote: >> On Wed, Oct 8, 2014, at 15:53, Ethan Furman wrote: >>> On 10/08/2014 12:49 PM, random832@fastmail.us wrote: >>>> On Wed, Oct 8, 2014, at 15:38, Ethan Furman wrote: >>>>> >>>>> LOL, no kidding! The main reason I bother using the operator >>>>> module is >>>>> for the readability of not seeing the dunders, >>>>> and the writability of not having to type them. >>>> >>>> I'm not sure what situation you would have to type them (as opposed to >>>> simply a + b) that the operator module would help with. >>> >>> unittest springs to mind: >>> >>> self.assertRaises(TypeError, op.add, obj1, obj2) >> >> Er, my point is, that is not a situation where you would be able to use >> obj1.__add__ - you'd have to use the operator module *anyway*, and >> therefore aren't using it just to get the convenience of a non-dunder >> name. > > self.assertRaises(TypeError, lambda x, y: x+y, obj1, obj2) Don't forget, in 2.7 you can do: with self.assertRaises(TypeError): obj1 + obj2 -- Ned Batchelder, http://nedbatchelder.com