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

Benjamin Han bhan at andrew.cmu.edu
Mon Apr 29 23:11:57 EDT 2002


On Monday 29 April 2002 10:02 pm, Cliff Wells wrote:
> On 29 Apr 2002 18:54:12 -0700
>
> Fortepianissimo wrote:
> > This question is so fundamental that I strongly suspect it's already
> > answered - ig that's the case, please forgive this poor newbie, for he
> > has done some work searching over Python FAQ and Google.
> >
> > Basically I want to have a subclass of list, like
> >
> > class MyList (list):
> >     ...
> >
> > then I want to
> >
> > l=MyList()
> > ... do stuff to fill l
> > s=" ".join(l)
>
> s = " ".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.

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? How much is an effort in converting Python into C++? Anyone 
would like to comment on some of these questions, or point to some article, 
FAQ (esp. helpful from a C++ programmer's point of view)?

Thanks for all those replied,

Ben



More information about the Python-list mailing list