Python .ends循环中缺少文件扩展名
我正在从这样的配置文件加载扩展名Python .ends循环中缺少文件扩展名,python,Python,我正在从这样的配置文件加载扩展名 search_ext = tuple((config.get("Miscellaneous", "media") + config.get("Miscellaneous", "meta") + config.get("Miscellaneous", "other")).split('|')) 在配置文件中,扩展名如下所示: 媒体=.mkv |
search_ext = tuple((config.get("Miscellaneous", "media") + config.get("Miscellaneous", "meta") + config.get("Miscellaneous", "other")).split('|'))
在配置文件中,扩展名如下所示:
媒体=.mkv |.avi |.divx |.xvid |.mov |.wmv |.mp4 |.mpg |.mpeg |.vob |.iso
meta=.nfo |.sub |.srt |.jpg |.jpeg |.gif |.txt
其他=.exe |.pdf
然后使用os.walk在文件列表中循环,使用.endswith进行搜索
if fileName.endswith(search_ext):
但它似乎总是错过最后一个扩展,如在本例中是.pdf。很容易通过添加一个伪扩展来规避,比如。未知的。但这是为什么呢?这与我的元组有关吗?去掉配置值周围的空格。(根据
config
,这可能不是问题所在)
media
的最后一个元素和meta
的第一个元素不带分隔符地连接在一起。(与元
,其他
相同)
search_ext = (
config.get("Miscellaneous", "media").strip() + '|' +
config.get("Miscellaneous", "meta").strip() + '|' +
config.get("Miscellaneous", "other").strip()
).split('|')