What are new-style classes?

Jan Danielsson jan.danielsson at gmail.com
Mon Aug 29 10:11:14 EDT 2005


Vaibhav wrote:
> I recently heard about 'new-style classes'. I am very sorry if this
> sounds like a newbie question, but what are they? I checked the Python
> Manual but did not find anything conclusive. Could someone please
> enlighten me? Thanks!

   In short: They have inherited "object" from somewhere. (This is
probably technically inaccurate, but it's the only thing I have seen
which defines a 'new-style class').

   What it means *practically*, is that you can use properties. For a
long while I didn't really understand the point or properties, until I
needed them.

   I have written a flowcharting application in Python. All objects on
the flowchat are derived from a base object which has the attribute
"text" (all objects have some form of, sometimes internal only, title).
Problem is that when some objects change text, I want to perform some
recalculations. So I wrote a "text" property, which - in its
settext-method - does all the calculations if required.

That way, the application can till use:

obj.text = 'Blah'

..and still have the chance to act on the text change.

   I could have simply written a setText() method, but imho properties
are neater - but that's just a matter of opinion.


-- 
Kind Regards,
Jan Danielsson
Te audire no possum. Musa sapientum fixa est in aure.



More information about the Python-list mailing list