我不知道什麼是錯在此代碼:「對於我在文件名中」創建一個類型錯誤
import os
import re
regex = re.compile(r'\d+')
for f in os.listdir("F:/temptest2/"):
fname = os.path.splitext(f)[0]
fext = os.path.splitext(f)[1]
if fext == ".DNG":
fdngnum = regex.findall(fname)
matchcount = 0
for i in os.listdir("F:/temptest2/"):
f2name = os.path.splitext(i)[0]
if fdngnum in f2name:
matchcount = matchcount + 1
if matchcount < 2:
print(f)
我上線if fdngnum in f2name:
TypeError: 'in <string>' requires string as left operand, not list
以下錯誤它說f2name應該是一個字符串而不是一個列表。但是這不是一個字符串? (我認爲它充當單個字符串,每個通過for循環)
謝謝!
「它說f2name應該是一個字符串,而不是一個列表。」不,它說fdngnum應該是一個字符串。左邊是另一邊。 – Evert