在Python中,我可以执行以下操作:
>>> list = ['a', 'b', 'c']
>>> ', '.join(list)
'a, b, c'
有对象列表时,有什么简单的方法可以做到这一点?
>>> class Obj:
... def __str__(self):
... return 'name'
...
>>> list = [Obj(), Obj(), Obj()]
>>> ', '.join(list)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: sequence item 0: expected string, instance found
还是我必须求助于for循环?