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
Post a Comment