Python 从listdir中删除OSx路径中的not.DS_存储和.localized

Python 从listdir中删除OSx路径中的not.DS_存储和.localized,python,operating-system,tuples,listdir,Python,Operating System,Tuples,Listdir,我正在创建一个所有路径的元组,但它还包含两个额外的路径 /Users/sanjeevkumar/Pictures/.DS_商店 /Users/sanjeevkumar/Pictures/。本地化 我如何摆脱上述路径, 我使用以下技术生成元组路径 tuple(os.path.join(self._path,each) for each in os.listdir(self._path) if os.path.isfile(os.path.join(self._path,each))) 使用和运算

我正在创建一个所有路径的元组,但它还包含两个额外的路径

  • /Users/sanjeevkumar/Pictures/.DS_商店
  • /Users/sanjeevkumar/Pictures/。本地化
  • 我如何摆脱上述路径, 我使用以下技术生成元组路径

    tuple(os.path.join(self._path,each) for each in os.listdir(self._path) if os.path.isfile(os.path.join(self._path,each)))
    

    使用
    运算符展开
    if
    子句

    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') # <-------------
    )
    
    元组(
    os.path.join(self.\u路径,每个)
    对于os.listdir(self.\u路径)中的每个
    if os.path.isfile(os.path.join(self.\u path,每个))
    
    而且每个都不在('.DS_Store','.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))
        and each.endswith('png') or each.endswith('jpg')
    )
    
    我认为这也将帮助我摆脱任何其他文件扩展名,可能出现和不兼容