def getfilename():
prefixed = [filename for filename in os.listdir(filelocation) if filename.startswith("V")]
print prefixed
return prefixed上面的函数给我一个错误"AttributeError:'listdir‘对象没有’listdir‘属性“
请帮我解决这个问题
发布于 2016-09-28 13:52:44
出现异常的原因是因为您在代码中的其他位置将os设置为None;而os是内置库的名称。
无论哪种方式,您的代码都复制了内置glob方法的功能;所以只需使用它:
import glob
import os
filelocation = '/path/to/the/directory'
def get_filename():
return glob.glob(os.path.join(filelocation, 'V*'))https://stackoverflow.com/questions/39738948
复制相似问题