pasztora
2/14/2019 - 3:07 PM

Error handling duplicated values in a list

# Searching for GDF numbers amongst the list of output files (used for error handling)
# FileList variable is refiltered for fermentation templates with GDF
# FileList contains a list of file paths for Excel files having GDF in their names
FileKeys_check = [re.search('GDF(.+?)(.+?)(.+?)(.+?)(.+?)',z).group(0) for z in FileList]

# Checking for duplicates in the list of output files and error handling
duplicated = sorted(list(set([x for x in FileKeys_check if FileKeys_check.count(x) > 1])))
if len(duplicated) > 0:
    print "ERROR: Duplicated files were found:"
    print ', '.join(duplicated)
    print "Please check these files. The script will terminate now"
    raw_input("Press ENTER to exit") # Waits for an input and leaves the console open
    exit() # The console window is closed
else:
    pass