我正在設置一個腳本來根據文件中包含的文本合併PDF。我在這裏的問題是「小提琴I」也包含在「小提琴II」中,並且「中音薩克斯管I」也包含在「中音薩克斯管II」中。我該如何設置,以便tempList只包含來自「Violin I」的條目並排除「Violin II」,反之亦然?分離其他地方包含的字符串
pdfList = ["01 Violin I.pdf", "02 Violin I.pdf","01 Violin II.pdf", "02 Violin II.pdf", ]
instruments = ["Soprano", "Tenor", "Violin I", "Violin II", "Viola", "Cello", "Contrabass", "Alto Saxophone I", "Alto Saxophone II", "Tenor Saxophone", "Baritone Saxophone"]
# create arrays for each instrument that can be used for merging/organization
def organizer():
for fileName in pdfList:
for instrument in instruments:
tempList = []
if instrument in fileName:
tempList.append(fileName)
print tempList
print pdfList
organizer()
PDF是否總是像這樣命名? IE瀏覽器。 '號碼+儀表+ .pdf'。或者我們是否應該假定PDF可以有任何包含該工具的名稱? – woemler 2013-03-23 16:22:39
是的,PDFs將始終採用格式「(初始數字)+(一些文本)+(儀器)+ .pdf – jumbopap 2013-03-23 16:23:37