我试图做一个功能,但我有以下问题:错误写有“LEN(LST)”的文件时,当它为空
File "/home/python/functions.py", line 298, in function
fileout.write("%i \n\n")%(len(lst_one))
TypeError: unsupported operand type(s) for %: 'NoneType' and 'int'
#lst_one
在脚本中正确定义。我认为这是因为lst_one
仍然是空的,所以%i
不起作用(%s
也不起作用)。
有没有办法避免TypeError?
@DeepSpace更好,使用'.format'方法! –
噢,太棒了..谢谢 – santimirandarp
@DeepSpace什么是.format?无论如何,谢谢 – santimirandarp