该报错是因为在print语句中,当你将一个整数(int)与字符串(str)进行连接时,会出现TypeError。解决这个问题的方法是将整数转换为字符串,然后再进行连接。

你可以使用str()函数将整数转换为字符串,修改代码如下:

print("file_size: " + str(file_size) + "\n" + "file_line_count: " + str(file_line_count))

这样就能够正常输出了。

printfile_size+file_size+n+file_line_count + file_line_count报错TypeError can only concatenate str not int to str

原文地址: https://www.cveoy.top/t/topic/i5Ne 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录