printing a sequence...

Dan Bishop danb_83 at yahoo.com
Fri Jul 16 18:31:46 EDT 2004


Christopher T King <squirrel at WPI.EDU> wrote in message news:<Pine.LNX.4.44.0407161004150.10067-100000 at ccc8.wpi.edu>...
> On Fri, 16 Jul 2004, Peter Otten wrote:
> 
> > Peter Otten wrote:
> > 
> > > Florian Preknya wrote:
>  
> > >> What I want to obtain is [value: 10, value: 12, value: 2].
>  
> > >> Can I write somehow the print statement to force calling the A.__str__
> > >> function?
> > > 
> > > print [str(item) for item in a]
> > 
> > print "[%s]" % ", ".join(map(str, a))
> 
> I had the same problem with the same solution, and it makes me wonder, why
> does a list's __str__() method call the __repr__() method of its members?  
> Personally, I think the __str__() call should be propagated, not turned 
> into a __repr__() call.  I can't think of any instances in which such 
> behavior is what you want (if the __repr__() of the members is wanted, 
> then __repr__() should be used).

seq = ['A, B', 'C']
print seq



More information about the Python-list mailing list