Check that a *type* of file exists in Python

后端 未结 6 696
囚心锁ツ
囚心锁ツ 2021-01-11 17:03

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

6条回答
  •  不知归路
    2021-01-11 17:12

    filenames = os.listdir(os.curdir)
    found = False
    for filename in filenames:
        if os.path.isfile(filename) and filename.endswith('.fna'):
            found = True
    if not found:
        sys.stderr.write ('No database file found. Exiting program. \n')
        sys.exit(-1)
    

提交回复
热议问题