今天在格式化输出时间元组时出现如下错误:
TypeError: not all arguments converted during string formatting
错误意思:不是所有的参数都可以转换为字符格式
源代码如下:
print(“当前本地时间为:time.localtime() = %s” %time.localtime())
解决办法如下:
修改代码如下:
print(“当前本地时间为:time.localtime() = %s” %(time.localtime(),))
原因分析如下:
%s只能格式化一个字符串,所以需要把time.localtime作为一个整体。