我编写了一个简单的for循环来提取目录中的所有mps文件。
for root, dirs, files in os.walk(rootDir, topdown='true'):
# filter the file names
for filename in files:
print(filename); # this prints out filenames as expected
print([file for filename in files if file[-4:] == '.mp3'])
我明白了:
TypeError: 'type' object is not subscriptable
有什么想法吗?
答案 0 :(得分:1)
print([filename for filename in files if filename[-4:] == '.mp3'])