On 25/09/2012 17:20, Steven D'Aprano wrote:
On Tue, 25 Sep 2012 07:44:04 -0700, Jayden wrote:
In learning Python, I found there are two types of classes? Which one
are widely used in new Python code?
New-style classes.
Is the new-style much better than old-style?
Yes.
Always use new-style classes, unless you have some specific reason for
needing old-style ("classic") classes.
Advantages of new-style classes:
1) They are the future. In Python 3, all classes are "new-style" and
classic classes are gone.
2) Multiple inheritance works correctly. Multiple inheritance for classic
classes is buggy.
3) New-style classes support awesome features like super(), properties,
descriptors, and __getattribute__. Old-style do not.
The main disadvantage is that automatic delegation is a pain to do
correctly in new-style classes, but trivially simple in classic classes.
Still, all things considered, it's a good trade.
Thanks for this reminder, my port of the J word code to Python has just
been simplified :)
--
Cheers.
Mark Lawrence.
--
http://mail.python.org/mailman/listinfo/python-list