bizarre id() results

2005-12-15 Thread Stuart McGraw
The following was cut and pasted exactly (except for the # lines which I added after the fact) from an interactive python session in a Window 2000 cmd.exe window. Can somebody please explain to me what the heck is going on?!?! Python 2.4.2 (#67, Sep 28 2005, 12:41:11) [MSC v.1310 32 bit

RE: bizarre id() results

2005-12-15 Thread Delaney, Timothy (Tim)
Stuart McGraw wrote: Python 2.4.2 (#67, Sep 28 2005, 12:41:11) [MSC v.1310 32 bit (Intel)] on win32 Type help, copyright, credits or license for more information. class A: ... def m1(self): print m1 ... def m2(self): print m2 ... a = A() a.m1() m1 a.m2() m2 # ok, both methods work

Re: bizarre id() results

2005-12-15 Thread Fredrik Lundh
Stuart McGraw wrote: The following was cut and pasted exactly (except for the # lines which I added after the fact) from an interactive python session in a Window 2000 cmd.exe window. Can somebody please explain to me what the heck is going on?!?! Python 2.4.2 (#67, Sep 28 2005, 12:41:11)

Re: bizarre id() results

2005-12-15 Thread Diez B. Roggisch
# ok, both methods work and give the expected results # so i presume they are different methods. id(a.m1) 9202984 id(a.m2) 9202984 id(a.m1)==id(a.m2) True # Huh? They seem to be the same. What you observe is rooted in two things: - python objects bound methods are created on

Re: bizarre id() results

2005-12-15 Thread Chris Lambacher
a.m1 returns a bound method which gets freed before you try checking a.m2, which ends up getting the same peice of memory. If you save a reference to the bound methods, they are forced to have separate objects. class A: ... def m1(self): print m1 ... def m2(self): print m2 ... a = A()

Re: bizarre id() results

2005-12-15 Thread Stuart McGraw
Delaney, Timothy (Tim) [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] and several other people responded with similar information. [...] Bound methods are created on the fly. [...] Ahhh! That was the piece I was missing. Thank you all! --