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
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
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
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
>
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
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
> 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
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."
>
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
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.
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)
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
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
13 matches
Mail list logo