An interesting difference between classic and new style objects

Pekka Pessi Pekka.Pessi at nokia.com
Sat Jan 12 15:39:15 EST 2002


In message <mailman.1010695218.16009.python-list at python.org> Oren Tirosh <oren-py-l at hishome.net> writes:
>Actually, the title of this thread is misleading.  I don't mind too much if 
>there are certain differences between classic and new style objects. The 
>problem is that Python code and builtin functions don't have the same view 
>of a new style object.  A builtin function sees only the methods the object 
>had at the time it was instantiated while Python code can see methods that 
>have been added or modified by assignment.  

	What is a difference of a method and an attribute? Method is
	always an attribute of the class. The new-style classes are
	immutable, so it is not possible to modify methods of a new
	style object.

	Please see Reference Manual section 3.3 "Special Method Names",
	and how the special methods are defined.

>Is the modification of an object's methods an officially supported language
>feature or is this considered messing with internal stuff?

	I'm afraid modification of object's methods is considered a wart
	nowadays. In the future (or even now?) it may be possible to
	change the __class__ attribute of the "new style" objects.

						Pekka




More information about the Python-list mailing list