0
我試圖編寫一些代碼來搜索目錄,並提取以特定數字(由列表定義)開始並以'.labels結尾的所有項目。文本'。這是我迄今爲止所擁有的。通過目錄搜索具有多個條件的項目
lbldir = '/musc.repo/Data/shared/my_labeled_images/labeled_image_maps/'
picnum = []
for ii in os.listdir(picdir):
num = ii.rstrip('.png')
picnum.append(num)
lblpath = []
for file in os.listdir(lbldir):
if fnmatch.fnmatch(file, '*.labels.txt') and fnmatch.fnmatch(file, ii in picnum + '.*'):
lblpath.append(os.path.abspath(file))
以下是錯誤我得到
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-10-a03c65e65a71> in <module>()
3 lblpath = []
4 for file in os.listdir(lbldir):
----> 5 if fnmatch.fnmatch(file, '*.labels.txt') and fnmatch.fnmatch(file, ii in picnum + '.*'):
6 lblpath.append(os.path.abspath(file))
TypeError: can only concatenate list (not "str") to list
我實現picnum部分II將無法正常工作,但我不知道如何解決它。這可以用fnmatch模塊來完成,還是需要正則表達式?