Re: AttributeError in "with" statement (3.2.2)

2011-12-17 Thread Terry Reedy
On 12/16/2011 8:26 PM, Steven D'Aprano wrote: On Fri, 16 Dec 2011 17:05:57 -0500, Terry Reedy wrote: It is am important distinction [unbound versus bound] It is not an important distinction, and I am not confusing the two. So we agree on the distinction but disagree on its importance. Let

Re: AttributeError in "with" statement (3.2.2)

2011-12-16 Thread Steven D'Aprano
On Fri, 16 Dec 2011 15:26:30 -0800, Ethan Furman wrote: > Terry Reedy wrote: >> On 12/16/2011 4:22 AM, Steven D'Aprano wrote: [...] > I think you two are in violent agreement as far as how Python is > functioning, and the conflict is in the names given to the various > pieces... I think a glossar

Re: AttributeError in "with" statement (3.2.2)

2011-12-16 Thread Steven D'Aprano
On Fri, 16 Dec 2011 17:05:57 -0500, Terry Reedy wrote: > On 12/16/2011 4:22 AM, Steven D'Aprano wrote: >> On Thu, 15 Dec 2011 19:39:17 -0500, Terry Reedy wrote: [...] >> >> After reading your post, I think I have worked out where our >> disagreement lines: you think that bound methods and instance

Re: AttributeError in "with" statement (3.2.2)

2011-12-16 Thread Ethan Furman
Ethan Furman wrote: Terry Reedy wrote: On 12/16/2011 4:22 AM, Steven D'Aprano wrote: On Thu, 15 Dec 2011 19:39:17 -0500, Terry Reedy wrote: [...] After reading your post, I think I have worked out where our disagreement lies: you think that bound methods and instance methods are not the same

Re: AttributeError in "with" statement (3.2.2)

2011-12-16 Thread Ethan Furman
Terry Reedy wrote: On 12/16/2011 4:22 AM, Steven D'Aprano wrote: On Thu, 15 Dec 2011 19:39:17 -0500, Terry Reedy wrote: [...] After reading your post, I think I have worked out where our disagreement lies: you think that bound methods and instance methods are not the same thing, Do you agree

Re: AttributeError in "with" statement (3.2.2)

2011-12-16 Thread Terry Reedy
On 12/16/2011 4:22 AM, Steven D'Aprano wrote: On Thu, 15 Dec 2011 19:39:17 -0500, Terry Reedy wrote: [...] After reading your post, I think I have worked out where our disagreement lines: you think that bound methods and instance methods are not the same thing, Do you agree that an unbound met

Re: AttributeError in "with" statement (3.2.2)

2011-12-16 Thread Steven D'Aprano
On Thu, 15 Dec 2011 19:39:17 -0500, Terry Reedy wrote: [...] After reading your post, I think I have worked out where our disagreement lines: you think that bound methods and instance methods are not the same thing, and that a function defined inside a class is different from a function outside

Re: AttributeError in "with" statement (3.2.2)

2011-12-15 Thread Steven D'Aprano
On Thu, 15 Dec 2011 05:35:55 -0800, Steve Howell wrote: > For the special methods like __enter__ and __exit__, the tricky part > isn't understanding what would happen once the methods were called; the > tricky part is getting them to be called in the first place, if they > were not declared inside

Re: AttributeError in "with" statement (3.2.2)

2011-12-15 Thread Terry Reedy
On 12/15/2011 12:01 AM, 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

Re: AttributeError in "with" statement (3.2.2)

2011-12-15 Thread Gregory Ewing
MRAB wrote: 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. Or the naked mole-rat. Or cetaceans (whales). The way I understand it, the main characteris

Re: AttributeError in "with" statement (3.2.2)

2011-12-15 Thread Steve Howell
On Dec 14, 9:01 pm, Steven D'Aprano wrote: > [...] > So what are methods? In Python, methods are wrappers around functions > which automatically pass the instance to the inner function object. Under > normal circumstances, you create methods by declaring functions inside a > class, but that's not

Re: AttributeError in "with" statement (3.2.2)

2011-12-14 Thread Steven D'Aprano
On Thu, 15 Dec 2011 05:01:21 +, Steven D'Aprano wrote: >> 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

Re: AttributeError in "with" statement (3.2.2)

2011-12-14 Thread Steven D'Aprano
On Thu, 15 Dec 2011 05:15:58 +, MRAB wrote: > 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

Re: AttributeError in "with" statement (3.2.2)

2011-12-14 Thread MRAB
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 *metho

Re: AttributeError in "with" statement (3.2.2)

2011-12-14 Thread Steven D'Aprano
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

Re: AttributeError in "with" statement (3.2.2)

2011-12-14 Thread Terry Reedy
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 take

Re: AttributeError in "with" statement (3.2.2)

2011-12-14 Thread Eric Snow
On Wed, Dec 14, 2011 at 12:14 PM, Lie Ryan wrote: > On 12/15/2011 03:56 AM, Eric Snow wrote: >> >> On Tue, Dec 13, 2011 at 11:05 PM, Eric Snow >>  wrote: >> >> If you want to be more dynamic about it you can do it, but it involves >> black magic.  Chances are really good that being explicit throug

Re: AttributeError in "with" statement (3.2.2)

2011-12-14 Thread Lie Ryan
On 12/15/2011 03:56 AM, Eric Snow wrote: On Tue, Dec 13, 2011 at 11:05 PM, Eric Snow wrote: If you want to be more dynamic about it you can do it, but it involves black magic. Chances are really good that being explicit through your class definition is the right approach. Note that the black

Re: AttributeError in "with" statement (3.2.2)

2011-12-14 Thread Steve Howell
On Dec 14, 12:01 am, Steven D'Aprano wrote: > [...] > > So the normal lookup rules that apply to data attributes, namely > instance, then class, then superclasses, also applies to methods in > Python. In languages that don't allow that sort of thing, like Java, you > need to use convoluted design

Re: AttributeError in "with" statement (3.2.2)

2011-12-14 Thread Eric Snow
On Tue, Dec 13, 2011 at 11:05 PM, Eric Snow wrote: > On Tue, Dec 13, 2011 at 10:42 PM, Steve Howell wrote: >> I'm using Python 3.2.2, and the following program gives me an error >> that I don't understand: >> >> class Foo: >>  pass >> >> foo = Foo() >> foo.name = "Steve" >> >> def add_goodbye_fun

Re: AttributeError in "with" statement (3.2.2)

2011-12-14 Thread 88888 Dihedral
On Thursday, December 15, 2011 12:08:32 AM UTC+8, 8 Dihedral wrote: > On Wednesday, December 14, 2011 4:01:24 PM UTC+8, 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 > > > ins

Re: AttributeError in "with" statement (3.2.2)

2011-12-14 Thread 88888 Dihedral
On Wednesday, December 14, 2011 4:01:24 PM UTC+8, 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

Re: AttributeError in "with" statement (3.2.2)

2011-12-14 Thread Peter Otten
Steve Howell wrote: > I'm using Python 3.2.2, and the following program gives me an error > that I don't understand: > > class Foo: > pass > > foo = Foo() > foo.name = "Steve" > > def add_goodbye_function(obj): > def goodbye(): > print("goodbye " + obj.name) > obj.goodbye = goodbye >

Re: AttributeError in "with" statement (3.2.2)

2011-12-14 Thread Steven D'Aprano
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 p

Re: AttributeError in "with" statement (3.2.2)

2011-12-13 Thread Terry Reedy
On 12/14/2011 1:05 AM, Eric Snow wrote: On Tue, Dec 13, 2011 at 10:42 PM, Steve Howell wrote: I'm using Python 3.2.2, and the following program gives me an error that I don't understand: class Foo: pass foo = Foo() foo.name = "Steve" def add_goodbye_function(obj): def goodbye(): prin

Re: AttributeError in "with" statement (3.2.2)

2011-12-13 Thread Eric Snow
On Tue, Dec 13, 2011 at 10:42 PM, Steve Howell wrote: > I'm using Python 3.2.2, and the following program gives me an error > that I don't understand: > > class Foo: >  pass > > foo = Foo() > foo.name = "Steve" > > def add_goodbye_function(obj): >  def goodbye(): >    print("goodbye " + obj.name)

AttributeError in "with" statement (3.2.2)

2011-12-13 Thread Steve Howell
I'm using Python 3.2.2, and the following program gives me an error that I don't understand: class Foo: pass foo = Foo() foo.name = "Steve" def add_goodbye_function(obj): def goodbye(): print("goodbye " + obj.name) obj.goodbye = goodbye add_goodbye_function(foo) foo.goodbye() # output