Python源码导出到一个txt文件
# -*- coding: utf-8 -*- """ @author: Mr_zhang @software: PyCharm @file: export.py @time: 2022/6/29 14:57 """ import os import re exclude_file = "device|residence|custom_file|user|public|management|setting|models|00|pyc|__|urls|filters|views" pattern = re.compile(exclude_file) BASEDIR = os.path.dirname(__file__) def read_dir(path): _file_list = [] for dir_path, dirs, files in os.walk(path): for file in files: file_path = os.path.join(dir_path, file) if "\\" in file_path: file_path = file_path.replace("\\", "/") if not pattern.search(file_path): _file_list.append(file_path) for _dir in dirs: _file_list.extend(read_dir(os.path.join(dir_path, _dir))) return _file_list if __name__ == '__main__': file_list = read_dir(os.path.join(BASEDIR, "apps")) print(len(file_list)) for item in file_list: print(item) # with open("code.txt", "w+") as w: # for file in file_list: # with open(file, "r") as f: # w.writelines(f.readlines())
本文来自博客园,作者:一石数字欠我15w!!!,转载请注明原文链接:https://www.cnblogs.com/52-qq/p/16423895.html
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· CSnakes vs Python.NET:高效嵌入与灵活互通的跨语言方案对比
· DeepSeek “源神”启动!「GitHub 热点速览」
· 我与微信审核的“相爱相杀”看个人小程序副业
· Plotly.NET 一个为 .NET 打造的强大开源交互式图表库
· 上周热点回顾(2.17-2.23)
2021-06-29 项目部署
2018-06-29 一套小学生的试卷。。。
2018-06-29 python基础小练习
2018-06-29 Django-配置celery