Re: question about the id()

2005-05-17 Thread Peter Dembinski
Giovanni Bajo [EMAIL PROTECTED] writes: Peter Dembinski wrote: 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

Re: question about the id()

2005-05-17 Thread Dan Sommers
On Tue, 17 May 2005 13:56:18 +0200, Peter Dembinski [EMAIL PROTECTED] wrote: Giovanni Bajo [EMAIL PROTECTED] writes: Peter Dembinski wrote: BTW, a typical performance optimization (not done automatically by python) is to hoist unchanging-value expressions out of loops, and obj.method is

Re: question about the id()

2005-05-16 Thread Andrew Dalke
kyo guan wrote: Can someone explain why the id() return the same value, and why these values are changing? Thanks you. a=A() id(a.f) 11365872 id(a.g) 11365872 The Python functions f and g, inside of a class A, are unbound methods. When accessed through an instance what's returned

Re: question about the id()

2005-05-16 Thread Peter Dembinski
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

Re: question about the id()

2005-05-16 Thread Andrew Dalke
Peter Dembinski wrote: So, the interpreter creates new 'point in address space' every time there is object-dot-method invocation in program? Yes. That's why some code hand-optimizes inner loops by hoisting the bound objection creation, as data = [] data_append = data.append for x in

Re: question about the id()

2005-05-16 Thread Bengt Richter
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

Re: question about the id()

2005-05-16 Thread Bengt Richter
On Mon, 16 May 2005 16:57:12 GMT, Andrew Dalke [EMAIL PROTECTED] wrote: Peter Dembinski wrote: So, the interpreter creates new 'point in address space' every time there is object-dot-method invocation in program? Yes. That's why some code hand-optimizes inner loops by hoisting the bound

Re: question about the id()

2005-05-16 Thread Peter Dembinski
[EMAIL PROTECTED] (Bengt Richter) writes: [snap] So, the interpreter creates new 'point in address space' every time there is object-dot-method invocation in program? [optimization] BTW, a typical performance optimization (not done automatically by python) is to hoist unchanging-value

Re: question about the id()

2005-05-16 Thread Giovanni Bajo
Peter Dembinski wrote: 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.

question about the id()

2005-05-15 Thread kyo guan
HI ALL: Can someone explain why the id() return the same value, and why these values are changing? Thanks you. Python 2.4.1 (#65, Mar 30 2005, 09:13:57) [MSC v.1310 32 bit (Intel)] on win32 Type help, copyright, credits or license for more information. class A(object): ... def f():

Re: question about the id()

2005-05-15 Thread Skip Montanaro
kyo Can someone explain why the id() return the same value, and why kyo these values are changing? Instance methods are created on-the-fly. In your example the memory associated with the a.f bound method (not the same as the unbound method A.f) is freed before you reference a.g. That

RE: question about the id()

2005-05-15 Thread kyo guan
:[EMAIL PROTECTED] Sent: Monday, May 16, 2005 11:09 AM To: kyo guan Cc: python-list@python.org Subject: Re: question about the id() kyo Can someone explain why the id() return the same value, and why kyo these values are changing? Instance methods are created on-the-fly

Re: question about the id()

2005-05-15 Thread Bengt Richter
On Mon, 16 May 2005 11:28:31 +0800, kyo guan [EMAIL PROTECTED] wrote: HI Skip: I want to check is there any change in the instance 's methods. a=A() a2=A() a.f == a2.f False a.f is a2.f False a.f is a.f False If the instance methods are create on-the-fly, how to do that?