[Tutor] new class vs. old class [was using class methods (security)]
Paul Tremblay
phthenry@earthlink.net
Fri, 26 Apr 2002 16:40:42 -0400
Sorry to be so dense on this issue, but I still am not sure about
the difference between new and old classes in python 2.2. Here is
an excerpt from the documentation linked to python.org:
http://www.amk.ca/python/2.2/
"First, you should know that Python 2.2 really has two kinds of classes: classic or old-style classes, and new-style
classes. The old-style class model is exactly the same as the class model in earlier versions of Python. All the new
features described in this section apply only to new-style classes. This divergence isn't intended to last forever;
eventually old-style classes will be dropped, possibly in Python 3.0.
"So how do you define a new-style class? You do it by subclassing an existing new-style class. Most of Python's
built-in types, such as integers, lists, dictionaries, and even files, are new-style classes now. A new-style class named
object, the base class for all built-in types, has been also been added so if no built-in type is suitable, you can
just subclass object:"
I understand that at this point I can continue using classes as
I have been in the past. However, what if I want to get in the
habit of writing new classes, since eventually I will have to?
According to the documentatin I quoted above, I *have* to
subclass new classes. (I am looking at the first sentence of the
second paragraph.)
In other words, when python 3.0 rolls around, I won't be able to
write this code:
class MyClass:
pass
Instead, won't I have to write
class MyClass(object):
pass
?
I have already downloaded the source rpm (I have linux) for
python 2.2. Maybe I should just go ahead and install it and play
around with it.
Thanks!
Paul
--
************************
*Paul Tremblay *
*phthenry@earthlink.net*
************************