在 Python 中,
logging.info('Followers: %d ', sum([a[1] for a in total])), 其中sum是一个整数并且total是list comprehension整数。我明白了,
TypeError: unsupported operand type(s) for +: 'int' and 'str'?? 不确定,为什么??
a[1]从列表返回的 Error 意味着total既是string也是integers。
例如。
In [9]: lis=[1,'foo',3]
In [10]: sum(lis)
TypeError: unsupported operand type(s) for +: 'int' and 'str'
因为[(123243, 3), (24532, 5)]您的代码工作正常:
In [17]: lis=[(123243, 3), (24532, 5)]
In [18]: 'Followers: %d '%sum([a[1] for a in lis])
Out[18]: 'Followers: 8 '