I realize this looks similar to other questions about checking if a file exists, but it is different. I\'m trying to figure out how to check that a type of
The for statement in Python has a little-known else
clause:
for filename in filenames:
if os.path.isfile(filename) and filename.endswith(".fna"):
# do stuff
break
else:
sys.stderr.write ('No database file found. Exiting program. \n')
sys.exit(-1)
The else
clause is run only if the for
statement runs through its whole enumeration without executing the break
inside the loop.