On Mon, 16 May 2005 18:30:47 +0200, Peter Dembinski <[EMAIL PROTECTED]> wrote:

>Skip Montanaro <[EMAIL PROTECTED]> writes:
>
>>     kyo> Can someone explain why the id() return the same value, and
>>     kyo> why these values are changing?
>>
>> Instance methods are created on-the-fly.  
>
>So, the interpreter creates new 'point in address space' every time
>there is object-dot-method invocation in program?

Yes, but you can save the result of the obj.method expression (that's what it 
is,
an expression). E.g.,

     bound_method = obj.method

after that, you can write

     bound_method()

or
     obj.method()

(of course, you can pass arguments too, depending on the signature,
remembering that the "self" instance parameter is already bound in
and does not need to be passed again to a bound method)

The obj.method() call will re-evaluate the obj.method expression,
and the bound_method() call will just call the previously created
bound method.

BTW, a typical performance optimization (not done automatically by python)
is to hoist unchanging-value expressions out of loops, and obj.method is
often such an expression, so you will this strategy when people try
to squeeze extra performance from their programs.

Regards,
Bengt Richter
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to