Python types

bruno at modulix onurb at xiludom.gro
Mon Mar 27 08:25:55 EST 2006


Dennis Lee Bieber wrote:
> On Mon, 27 Mar 2006 01:34:14 +0200, Bruno Desthuilliers
> <bdesth.quelquechose at free.quelquepart.fr> declaimed the following in
> comp.lang.python:
> 
> 
>>Ok, so even if Python itself declares b and b2 (read: objects that names 
>>b and b2 are bound to) to be of the same type,  you cannot apply the 
>>myop() operation on b2...
> 
> 
>  
> 	Try looking at class-based objects as a form of CONTAINER... 

ouch, my ears :(

> Two
> containers can be of the same type, but the contents may be different.
> 
(snip)

This is mostly how OO is implemented in Python (in javascript too FWIW)
- but this is not the semantic of classes/objects in OO. The OO
translation of a type - at least according to the definition proposed by
the OP, and this is a pretty common definition - is a set of attributes
and methods. In most OO languages, this set is fixed for *all* the
instances of a class (subclassing not withstanding - and subclassing is
already a not so trivial problem in type theory).

What I wanted to point out is that, while class-based, Python in, in
this respect, closer to a prototype-based language.

In fact, since the set of attributes and methods of a given object may
change during the object's lifetime, it's type(s) may change too. So
saying that objects in Python "have a perfectly defined type" is perhaps
not really accurate, or at least requires further precisions (well, IMHO)

And I didn't even mention the possibility of changing the value of
anobject.__class__ at runtime !-)


-- 
bruno desthuilliers
python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in 'onurb at xiludom.gro'.split('@')])"



More information about the Python-list mailing list