最佳答案
在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循环?