import os
import sys
listed=[]
for folderName,subfolders,filenames in os.walk('/'):
for filename in filenames:
if filename.endswith('.png'):
listed.append(filename)
for name in range(len(list(0,10))):
print(name)
/我希望此脚本查找所有.png文件,但最多只能打印10个,但运行脚本时会出现错误:“TypeError:list最多需要1个参数,Get 2”我如何修复此问题
如果要打印
.png
文件名,可以这样做:但是你得到的
TypeError
是因为:for name in range(len(list(0,10))):
您向
range
函数传递了end
参数,以从0
迭代到end - 1
。没关系。但问题是要在哪里创建列表以及列表的长度。list
函数接受类似tuple
的迭代器因此,您可以通过以下方式实现:
但如果您想打印多达10个文件名,只需使用:
相关问题 更多 >
编程相关推荐