我正在为所有路径创建一个元组,但它也包含两个额外的路径。
/Users/sanjeevkumar/Pictures/.DS_Store/Users/sanjeevkumar/Pictures/.localized如何摆脱上述路径,我正在使用以下技术生成元组路径
tuple(os.path.join(self._path,each) for each in os.listdir(self._path) if os.path.isfile(os.path.join(self._path,each)))发布于 2013-11-17 03:09:51
另外,我也意识到我可以这样做。
tuple(os.path.join(self._path,each)
for each in os.listdir(self._path)
if os.path.isfile(os.path.join(self._path,each))
and each.endswith('png') or each.endswith('jpg')
)我认为这也将帮助我摆脱任何其他可能出现和不兼容的文件扩展名。
发布于 2013-11-16 12:31:55
使用if运算符展开and子句。
tuple(
os.path.join(self._path,each)
for each in os.listdir(self._path)
if os.path.isfile(os.path.join(self._path,each))
and each not in ('.DS_Store', '.localized') # <-------------
)https://stackoverflow.com/questions/20018466
复制相似问题