Discuss / Python / 这样比较简洁

这样比较简洁

Topic source

漫步立冬

#1 Created at ... [Delete] [Delete and Lock User]

def find_dir(s = '.py', path = '.'):

      path_abs = os.path.abspath(path)

      for i in [x for x in os.listdir(path_abs) if os.path.isfile(os.path.join(path_abs, x))]:

          if s in i:

              print(os.path.join(path_abs,i))

      for i in [x for x in os.listdir(path_abs) if os.path.isdir(os.path.join(path_abs, x))]:

          path_new = os.path.join(path_abs, i)

          find_dir(s,path_new)

find_dir(s = '.py', path = '/home/ismail/python')


  • 1

Reply