Newbie question: how to join a list of elements of user-defined types?

Kragen Sitaker kragen at pobox.com
Thu May 2 13:46:48 EDT 2002


Benjamin Han <bhan at andrew.cmu.edu> writes:

> On Monday 29 April 2002 10:02 pm, Cliff Wells wrote:
> > On 29 Apr 2002 18:54:12 -0700
> > s =3D " ".join([str(i) for i in l])
> 
> This surely looks nicer. I'm just wondering how far Python has fared in 
> terms of this concept of OO? This example seems to show a very different 
> character of OO in Python, in that __str__ is not automatically called, 
> which seems rather counter-intuitive.

Automatically calling __str__ is an instance of the language feature
called "implicit coercion".  It is not an OO feature.  Python does
comparatively few implicit coercions; in my experience, this makes
Python less bug-prone.

It is admittedly counterintuitive for programmers who are primarily
experienced with bug-prone languages in which implicit coercions lie
in wait around every corner, such as C++.

> Without private members, and with seemingly complex ways of dealing with
> class members and methods - so what's the state of OO in Python? Is it still
> rapidly evolving?

Apparently; class members and methods are a brand new addition in
Python 2.2.  I think they are a major design error; they add no power
but significant complexity to the language, and they are clumsy to
use and bug-prone.

> How much is an effort in converting Python into C++?

I am glad Python is not C++.  I enjoy Python much more than C++
because of those differences.




More information about the Python-list mailing list