Why the identifier of the object will change depending on the line in the python shell

These questions are just out of curiosity.

While I was reading the python object model documentation , I decided to experiment a bit with the class method identifier and found this:

 Python 3.2.2 (default, Sep  4 2011, 09:07:29) [MSC v.1500 64 bit (AMD64)] on win32
 Type "copyright", "credits" or "license()" for more information.
 >>> class A():
    def a(self):
        pass


 >>> id(A().a)
 54107080
 >>> id(A().a)
 54108104
 >>> id(A().a)
 54107080
 >>> id(A().a)
 54108104
 >>> 
 >>> id(A().a)
 54108104
 >>> 
 >>> id(A().a)
 54108104
 >>> id(A().a)
 54107080
 >>> 

The method identifier changes with line parity!

I really wanted to create a couple of instances of the same class and see if they have the same method object, and I expected that they would be the same or change every time that I did not expect, the method identifier would be associated with the string the translation is even even! Any ideas?

Note. I know that there is a discrepancy between the version from the documents and the interpreter, it just happens that I am in the windows and I only have 3.2

+2
1

, id(A().a) :

A() # creates a new object I call a

A().a # creates a function f bound to a
A.a.__get__(A(), A) # same as above

>>> A.a.__get__(A(), A)
<bound method A.a of <__main__.A object at 0x02D85550>>
>>> A().a
<bound method A.a of <__main__.A object at 0x02D29410>>

, __self__

>>> a = A()
>>> assert a.a.__self__ is a

__self__ self A.a

EDIT: :

Python 3.3.0 (v3.3.0:bd8afb90ebf2, Sep 29 2012, 10:55:48) [MSC v.1600 32 bit (Intel)] on win32
Type "copyright", "credits" or "license()" for more information.
>>> class A:
    def a(self):
        pass


>>> id(A().a)
43476312
>>> id(A().a)
49018760

id abab

Python 3.2.2 (default, Sep  4 2011, 09:51:08) [MSC v.1500 32 bit (Intel)] on win32
Type "copyright", "credits" or "license()" for more information.
>>> class A:
    def a(self):
        pas
        s


>>> id(A().a)
50195512
>>> id(A().a)
50195832
>>> id(A().a)
50195512
>>> id(A().a)
50195832

EDIT: Linux

id(A().a)

, , . , , , - . , .

+2

All Articles