python读取文件时按数字大小顺序排列

    def extract_number(filename):
        # 提取文件名中的数字部分
        return int(''.join(filter(str.isdigit, filename)))
    target_list = sorted(os.listdir(path),key=extract_number)

这样就行了

posted @ 2023-11-28 20:16  子过杨梅  阅读(136)  评论(0编辑  收藏  举报