listdir仅返回文件名:https
://docs.python.org/2/library/os.html#os.listdir您需要完整路径才能打开文件。在打开文件之前,还要检查以确保它是文件。下面的示例代码。
for filename in os.listdir(seqdir): fullPath = os.path.join(seqdir, filename) if os.path.isfile(fullPath): in_file = open(fullPath,'r') #do you other stuff
但是,对于文件,最好使用with关键字打开。即使有例外,它也会为您处理关闭。有关详细信息和示例,请参见https://docs.python.org/2/tutorial/inputoutput.html#methods-
of-file-objects



