Jayden wrote: > In the Python Tutorial, Section 9.4, it is said that > > "Data attributes override method attributes with the same name."
The tutorial is wrong here. That should be "Instance attributes override class attributes with the same name." As methods are usually defined in the class and data attributes are usually set in the instance it will look like data override method attributes. What the author had in mind: >>> class A: ... def i(self): print "method" ... >>> >>> a = A() >>> a.i() method >>> a.i = 42 # this could also happen in a method with self.i = 42 >>> a.i() Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: 'int' object is not callable >>> a.i 42 > But in my testing as follows: > > #Begin > class A: > i = 10 > def i(): > print 'i' > > A.i > <unbound method A.i> > #End but class A: def i(self): print "i" i = 42 print A().i # 42 If two objects are assigned to the same name the last assignment always wins. > I think A.i should be the number 10 but it is the method. There must be something I misunderstand. Would you please tell me why? No, you're right. Please file a bug report at http://bugs.python.org -- http://mail.python.org/mailman/listinfo/python-list