1. 程式人生 > >Python TypeError: coercing to Unicode: need string or buffer, float found

Python TypeError: coercing to Unicode: need string or buffer, float found

除錯Python程式:

unique_key = name + time.mktime(create_time.timetuple())

提示錯誤:

TypeError: coercing to Unicode: need string or buffer, float found

錯誤原因:使用“+”拼接會丟擲異常,改用%操作符輸出

    unique_key = u'%s%s' % (name, time.mktime(create_time.timetuple()))