Discuss / Python / 有个小疑问

有个小疑问

Topic source

参数path需要设置原始字符串才能使用。怎么样可以不用设置成原始字符串,在函数中处理输入的path

#!/usr/bin/env python3
# coding=utf-8

import os

def search(path=".", name="1"):
    for item in os.listdir(path):
        item_path = os.path.join(path, item)
        if os.path.isdir(item_path):
            sub_path = os.path.join(path, item)
            search(sub_path, name)
        elif os.path.isfile(item_path):
            if name in item:
                print("path={}\\{}".format(path, item))

if __name__ == "__main__":
    search(path="D:\\360",name="dll")

廖雪峰

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

参考“使用模块”一节:用sys模块


  • 1

Reply