Discuss / Python / 作业

作业

Topic source

太阳尚远Y

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

def find(path):
    # dirs = os.listdir(path)

    if os.path.isdir(path):
        for d in os.listdir(path):
            newdir = os.path.join(path, d)
            find(newdir)
    else:
        if os.path.splitext(path)[1] == '.py':
            print(path)

find('/home/idouby/PycharmProjects')

太阳尚远Y

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

第二版

import os

def find(path, key):
    if os.path.isdir(path):
        for d in os.listdir(path):
            newdir = os.path.join(path, d)
            find(newdir, key)
    else:
        if key in os.path.split(path)[1]:
            print(path)
find(input('the dir: '), input('tht key: '))

  • 1

Reply