python - Looping thorugh file names more than necessary -


i have following code

    if inputfilename:          if inputfilename.lower().endswith(mediaext):             word in ignorewords:                 if word not in inputfilename.lower():                     if os.path.isfile(inputdirectory):                         try:                             processfile(fileaction, inputdirectory, outputdestination)                         except exception, e:                             logging.error(loggerheader + "there error when trying process file: %s", os.path.join(inputdirectory, inputfilename))                             logging.exception(e)                     else:                         try:                             processfile(fileaction, os.path.join(inputdirectory, inputfilename), outputdestination)                         except exception, e:                             logging.error(loggerheader + "there error when trying process file: %s", os.path.join(inputdirectory, inputfilename))                             logging.exception(e) 

ignorewords list containing few words dont want filename contain. issue loop through same file x items in list. i'd match words once (or run processfile once when matching done) not quite able find proper solution it

replace

for word in ignorewords:     if word not in inputfilename.lower(): 

with

if not any(word in inputfilename.lower() word in ignorewords): 

Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -