Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed6.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.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'context': 0.04; 'attribute': 0.07; 'terry': 0.07; 'python': 0.08; '>>>>': 0.09; 'defined.': 0.09; 'from:addr:python': 0.09; 'parameter.': 0.09; 'am,': 0.12; 'definition,': 0.16; 'definition.': 0.16; 'from:addr:mrabarnett.plus.com': 0.16; 'from:name:mrab': 0.16; 'manager)': 0.16; 'message-id:@mrabarnett.plus.com': 0.16; 'received:84.92': 0.16; 'received:84.92.122': 0.16; 'received:84.92.122.60': 0.16; 'received:84.93': 0.16; 'received:84.93.230': 0.16; 'reedy': 0.16; 'reply-to:addr:python- list': 0.16; 'wed,': 0.17; 'wrote:': 0.18; '>>>': 0.18; 'instance': 0.18; 'purposes,': 0.18; 'dec': 0.22; 'header:In- Reply-To:1': 0.22; 'statement': 0.23; 'body.': 0.23; 'fine,': 0.23; 'defined': 0.24; 'says': 0.25; 'saying': 0.26; "i'm": 0.26; 'function': 0.27; 'subject:" ': 0.28; 'bit': 0.28; 'class': 0.29; 'correct': 0.29; 'definition': 0.30; '(the': 0.30; 'header:User- Agent:1': 0.33; 'actually': 0.33; 'there': 0.33; 'to:addr:python- list': 0.34; 'eric': 0.34; 'received:84': 0.34; 'too': 0.34; 'anything': 0.34; 'reply-to:addr:python.org': 0.34; 'subject:with': 0.36; 'but': 0.37; 'except': 0.37; 'technical': 0.37; 'think': 0.37; 'cases,': 0.38; 'steven': 0.38; 'created': 0.38; 'subject: (': 0.40; 'to:addr:python.org': 0.40; '2011': 0.61; 'covers': 0.64; 'birth': 0.67; 'header:Reply-To:1': 0.71; 'reply-to:no real name:2**0': 0.72; 'below:': 0.80; '-0500,': 0.84; 'naked': 0.91; 'live.': 0.95 X-CM-Score: 0.00 X-CNFS-Analysis: v=2.0 cv=J8QoHXbS c=1 sm=1 a=0nF1XD0wxitMEM03M9B4ZQ==:17 a=9jsOeB20M3cA:10 a=pZbEeqlyqr0A:10 a=OUOv7kDek9cA:10 a=8nJEP1OIZ-IA:10 a=hpdPqvloxCKxfb4ujJEA:9 a=wPNLvfGTeEIA:10 a=0nF1XD0wxitMEM03M9B4ZQ==:117 X-AUTH: mrabarnett:2500 Date: Thu, 15 Dec 2011 05:15:58 +0000 From: MRAB User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:8.0) Gecko/20111105 Thunderbird/8.0 MIME-Version: 1.0 To: python-list@python.org Subject: Re: AttributeError in "with" statement (3.2.2) References: <4ee857d4$0$11091$c3e8da3@news.astraweb.com> <4ee97f20$0$11091$c3e8da3@news.astraweb.com> In-Reply-To: <4ee97f20$0$11091$c3e8da3@news.astraweb.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 Precedence: list Reply-To: python-list@python.org 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: 34 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1323926134 news.xs4all.nl 6848 [2001:888:2000:d::a6]:58149 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:17251 On 15/12/2011 05:01, Steven D'Aprano wrote: > On Wed, 14 Dec 2011 18:13:36 -0500, Terry Reedy wrote: > >> On 12/14/2011 3:01 AM, Steven D'Aprano wrote: >>> On Wed, 14 Dec 2011 01:29:13 -0500, Terry Reedy wrote: >>> >>>> To complement what Eric says below: The with statement is looking for >>>> an instance *method*, which by definition, is a function attribute of >>>> a *class* (the class of the context manager) that takes an instance of >>>> the class as its first parameter. >>> >>> I'm not sure that is correct... I don't think that there is anything >>> "by definition" about where methods live. >> >> From the Python glossary: >> "method: A function which is defined inside a class body." >> >> That is actually a bit too narrow, as a function can be added to the >> class after it is defined. But the point then is that it is treated as >> if defined inside the class body. > > First off, let me preface this by saying that I'm not necessarily saying > that the above glossary definition needs to be changed. For most > purposes, it is fine, since *nearly always* methods are created as > functions defined inside the class body. But it needs to be understood in > context as a simplified, hand-wavy definition which covers 99% of the > common cases, and not a precise, definitive technical definition. > > To give an analogy, it is like defining mammals as "hairy animals which > give birth to live young", which is correct for all mammals except for > monotremes, which are mammals which lay eggs. > [snip] Or the naked mole-rat. Or cetaceans (whales).