AttributeError in "with" statement (3.2.2)
MRAB
python at mrabarnett.plus.com
Thu Dec 15 00:15:58 EST 2011
More information about the Python-list mailing list
Thu Dec 15 00:15:58 EST 2011
- Previous message (by thread): AttributeError in "with" statement (3.2.2)
- Next message (by thread): AttributeError in "with" statement (3.2.2)
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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).
- Previous message (by thread): AttributeError in "with" statement (3.2.2)
- Next message (by thread): AttributeError in "with" statement (3.2.2)
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-list mailing list