0
def get_houseid_list():
"""Returns a list of all house ids from db"""
print 'Building list of all HouseIDs...'
houseid_list = []
houseids = session.query(Episode.HouseID).all()
for i in houseids:
houseid_list.append(i[0])
return houseid_list
def walkDir(top, ignore=[]):
"""Returns a complete list of files from a directory, recursing through subfolders"""
print 'Building list of files...'
fflist = []
for root, dirs, files in os.walk(top):
dirs[:] = [ dn for dn in dirs if dn not in ignore ]
file_list = [name for name in files if name[0] != '.']
if len(file_list):
for f in file_list:
try:
houseid_parse(f)
print 'adding...', f
[fflist.append(join(root, f)) for f in file_list]
except HouseIdException:
print 'skipping...', f
print 'Found', len(file_list), 'files in', root
return fflist
def get_nonmatches(houseid_list, finallist):
print 'Comparing files to HouseIDs...'
nonmatches = []
for id in houseid_list:
print 'Searching for files to match', id
for f in finallist:
if re.search(id, f, re.IGNORECASE):
nonmatches.append(f)
return nonmatches
def writeCSV(nonmatch):
print 'Writing nonmatches to CSV...'
csv.write('%s' % nonmatch)
if __name__ == "__main__":
houseid_list = get_houseid_list()
print len(houseid_list), 'HouseIDs found'
wdirs = ['/Volumes/Assets/Projects']
finallist = []
for d in wdirs:
fflist = walkDir(d)
for f in fflist:
nonmatches = get_nonmatches(houseid_list,f)
print 'nonmatches', nonmatches
哪一部分無限循環? – 2010-07-20 06:51:22
我有點困惑'fflist.append(join(root,f))for file_list]''''''你有'join'函數定義了什麼地方嗎?或者這是類似於'from os.path import join'的行的結果? – 2010-07-20 06:56:54
只是要指出:看起來像不匹配每次在fflist的循環中被覆蓋。可能會使用擴展? nonmatches.extend(get_nonmatches(houseid_list,f)) – dmitko 2010-07-20 07:10:40