Diff. between Class types and classic classes
Colin J. Williams
cjw at sympatico.ca
Tue Nov 8 18:49:43 EST 2005
bruno at modulix wrote:
> venk wrote:
>
>>Hi,
>> can some one properly explain the differences between class types and
>>classic classes? ... Still face problems in identifying what is what.
>
>
> I'm not sure I understand your question. Are you talking about the diff
> between old-style and new-style classes, or the diff between classes and
> metaclasses ?
>
"new" classes inherit from object. Classic classes do not.
"new" classes have a __new__ method. Classic classes generally do not.
The type of a "new" class is types.TypeType
The type of a classic class is a classobj
The type of an instance of a "new" class is the name of the class
The type of an instnce of a classic class is an instance
This is shown below:
>>> class A(object):
... def __init__(self):
... pass
...
>>> a= A()
>>> class B:
... def __init__(self):
... pass
...
>>> b= B()
>>> type(A)
<type 'type'>
>>> type(a)
<class '__main__.A'>
>>> type(B)
<type 'classobj'>
>>> type(b)
<type 'instance'>
>>>
I hope that this helps.
Colin W.
More information about the Python-list
mailing list