Why can't I join this tuple in Python?
问题 e = ('ham', 5, 1, 'bird') logfile.write(','.join(e)) I have to join it so that I can write it into a text file. 回答1: join only takes lists of strings, so convert them first >>> e = ('ham', 5, 1, 'bird') >>> ','.join(map(str,e)) 'ham,5,1,bird' Or maybe more pythonic >>> ','.join(str(i) for i in e) 'ham,5,1,bird' 回答2: join() only works with strings, not with integers. Use ','.join(str(i) for i in e) . 回答3: You might be better off simply converting the tuple to a list first: e = ('ham', 5, 1,