samedi 9 juillet 2016

Is this the proper way to use assert in Python 3.5?


Is this the proper way to use assert?

My program takes some files names as command line arguments and stores them in a list. I need to cross reference the list of file names with names in a metadata file. If one of the files isn't in the metadata, I want the program to end and explain why. I thought assert might be good for that but I'm not sure if this is the proper way to use it or if there is a better way to iterate over a list and make sure it exists in the metadata.

for sample in samples_list:
    assert(sample in meta_sampleIds), "A file is missing from the metadata"

Aucun commentaire:

Enregistrer un commentaire