我被赋予了一项任务,即可以将读取所有MP3文件的函数更改为读取Mutagen能够读取的任何类型的文件。我想用手工做吗? (I.E如果.endswith = this或that),或者是否有通用的方法来实现这一目标?
循环的方式如下:
for root, dirs, files in os.walk("."):
for filename in files:
if filename.lower().endswith(".mp3"):
fullname = os.path.join(root, filename)
答案 0 :(得分:-1)
supported = ['.mp3','.ogg','.wma'] #put all known here
for root, dirs, files in os.walk("."):
for filename in files:
if filename.lower() in supported: #test if filename ext is in supported
fullname = os.path.join(root, filename)