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

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

这样就行了

posted @   子过杨梅  阅读(143)  评论(0编辑  收藏  举报
努力加载评论中...
点击右上角即可分享
微信分享提示