I've already looked at this question on representing strings in Python but my question is slightly different. It is also different than the question How to concatenate (join) items in a list to a single string which was created after this question and applies to a list of strings and thus does not have any applicability to this question whatsoever (where the thrust of this question is specifically dealing with the challenge of non-string items).
Here's the code:
>>> class WeirdThing(object):
... def __init__(self):
... self.me = time.time()
... def __str__(self):
... return "%s" % self.me
... def __repr__(self):
... return ";%s;" % self.me
...
>>> weird_list = [WeirdThing(), WeirdThing(), WeirdThing()]
>>> print weird_list
[;1302217717.89;, ;1302217717.89;, ;1302217717.89;]
>>> "\n".join(weird_list)
Traceback (most recent call last):
File "<console>", line 1, in <module>
TypeError: sequence item 0: expected string, WeirdThing found
I realize that this works:
>>> "\n".join(str(wi) for wi in weird_list)
'1302217717.89\n1302217717.89\n1302217717.89'
>>>
Still it would be nice to avoid doing that every time I want to join the objects together. Is it simply not possible?