Re: method = Klass.othermethod considered PITA

2005-06-07 Thread John J. Lee
Steven Bethard <[EMAIL PROTECTED]> writes: > John J. Lee wrote: > > Steven Bethard <[EMAIL PROTECTED]> writes: > >>In Python 2.4: > >> > >>py> class A(object): > >>... def foo(self): > >>... print 'foo' > >>... bar = foo > >>... > >>py> import pickle > >>py> pickle.loads(pickle.dump

Re: method = Klass.othermethod considered PITA

2005-06-07 Thread John J. Lee
Erik Max Francis <[EMAIL PROTECTED]> writes: [...] > requesting. In my particular case, there isn't much need to make sure > things are properly overridden in subclasses, since functionality > tends to get added, rather than modified. (The "Why would you want to [...] Well done, have this gold s

Re: method = Klass.othermethod considered PITA

2005-06-05 Thread Erik Max Francis
Steven Bethard wrote: > Well if you want these to work with subclasses that change verb_hello to > do something else, one option is to write a simple decorator, and then > your lines above become something like: Note I was just giving a use case for the general construct, not necessarily a use

Re: method = Klass.othermethod considered PITA

2005-06-05 Thread Steven Bethard
John J. Lee wrote: > Steven Bethard <[EMAIL PROTECTED]> writes: >>In Python 2.4: >> >>py> class A(object): >>... def foo(self): >>... print 'foo' >>... bar = foo >>... >>py> import pickle >>py> pickle.loads(pickle.dumps(A)).bar >> >>py> pickle.loads(pickle.dumps(A())).bar() >>foo >

Re: method = Klass.othermethod considered PITA

2005-06-05 Thread John J. Lee
Jeff Epler <[EMAIL PROTECTED]> writes: > On Sat, Jun 04, 2005 at 10:43:39PM +, John J. Lee wrote: > > 1. In derived classes, inheritance doesn't work right: > > Did you expect it to print 'moo'? I'd have been surprised, and expected > the behavior you got. Me too. It's at the time of *writ

Re: method = Klass.othermethod considered PITA

2005-06-05 Thread John J. Lee
Steven Bethard <[EMAIL PROTECTED]> writes: > John J. Lee wrote: > > It seems nice to do this > > class Klass: > > def _makeLoudNoise(self, *blah): > > ... > > woof = _makeLoudNoise > > Out of curiosity, why do you want to do this? I don't. It's just a habit I picked up from the

Re: method = Klass.othermethod considered PITA

2005-06-05 Thread Terry Reedy
> Steven Bethard wrote: > >> John J. Lee wrote: >> >>> It seems nice to do this >>> >>> class Klass: >>> >>> def _makeLoudNoise(self, *blah): >>> ... >>> >>> woof = _makeLoudNoise >> >> Out of curiosity, why do you want to do this? I have occasionally seen this usage where it made

Re: method = Klass.othermethod considered PITA

2005-06-04 Thread Steven Bethard
Erik Max Francis wrote: > For instance, for a chat network bot framework, a certain form of bot > will look for any attribute in its instance that starts with verb_ and a > command and execute it when it hears it spoken: > > def verb_hello(self, convo): > "Respond to a greeting." >

Re: method = Klass.othermethod considered PITA

2005-06-04 Thread Erik Max Francis
Steven Bethard wrote: > John J. Lee wrote: > >> It seems nice to do this >> >> class Klass: >> >> def _makeLoudNoise(self, *blah): >> ... >> >> woof = _makeLoudNoise > > Out of curiosity, why do you want to do this? There aren't too many clear use cases, but I've found it usef

Re: method = Klass.othermethod considered PITA

2005-06-04 Thread Jeff Epler
On Sat, Jun 04, 2005 at 10:43:39PM +, John J. Lee wrote: > 1. In derived classes, inheritance doesn't work right: Did you expect it to print 'moo'? I'd have been surprised, and expected the behavior you got. > 2. At least in 2.3 (and 2.4, AFAIK), you can't pickle classes that do >this.

Re: method = Klass.othermethod considered PITA

2005-06-04 Thread Leif K-Brooks
John J. Lee wrote: > class Klass: > > def _makeLoudNoise(self, *blah): > ... > > woof = _makeLoudNoise > > [...] > > At least in 2.3 (and 2.4, AFAIK), you can't pickle classes that do > this. Works for me: Python 2.3.5 (#2, May 4 2005, 08:51:39) [GCC 3.3.5 (Debian 1:3.3.5-12)

Re: method = Klass.othermethod considered PITA

2005-06-04 Thread Steven Bethard
John J. Lee wrote: > It seems nice to do this > > class Klass: > > def _makeLoudNoise(self, *blah): > ... > > woof = _makeLoudNoise Out of curiosity, why do you want to do this? > 1. In derived classes, inheritance doesn't work right: > > class A: > ... def foo(s):print

method = Klass.othermethod considered PITA

2005-06-04 Thread John J. Lee
It seems nice to do this class Klass: def _makeLoudNoise(self, *blah): ... woof = _makeLoudNoise One probably wants the above to work as if you'd instead defined woof in the more verbose form as follows: def woof(self, *blah): return self._makeLoudNoise(self, *blah) It do