def cut(path):
test = str(foundfiles)
newList = [s for s in test if test.endswith('.UnitTests.vbproj')]
for m in newList:
print m
return newList
這個函數解析foundliles,這是一個文件夾中的文件列表,我已經解析了大約20多個文件。我需要通過「.UnitTests.vbproj」中的每個文件結尾解析這個列表。但是,我無法得到它的工作。任何建議將不勝感激!爲什麼不用這個循環工作
EDIT1:這就是我現在做了我的代碼,我得到的atrribute錯誤消息框,說「元組」對象有沒有屬性「的endsWith」
def cut(path):
test = foundfiles
newList = [s for s in foundfiles if s.endswith('.UnitTests.vbproj')]
for m in newList:
print m
return newList
當你說*我無法得到它的工作*,你是什麼意思的工作/不工作? – Maroun
我強烈懷疑foundfiles實際上並不是一個字符串列表,而是一個包含一個字符串的元組列表。當然,如果是這樣的話,''將是一個元組,而不是一個字符串。 – kampu
重複的問題:[此循環應該工作,但它不是](http://stackoverflow.com/q/16587764/214178) – artdanil