import re
import os
import glob
# search all files inside a specific folder
# *.* means file name with any extension
dir_path = r'E:/pbrt-v3/src/**\*.*'
for file in glob.glob(dir_path, recursive=True):
if not file.endswith(('.h', '.cpp', '.c', '.hpp')):
print("file_name, ", file)
continue
file_content = ''
try:
with open(file, 'r', encoding='utf-8') as file_obj:
flag = 0
for line in file_obj:
file_content += line
if flag == 0 and re.match(r'.*class.*', line):
print(line.split(' ')[1])
flag = 1
elif flag ==1 and (re.match(r'.*public:.*', line) or re.match(r'.*private:.*', line) or re.match(r'.*protected:.*', line)):
flag = 2
file_content += "CLASS_FINED"
except:
print('error catched', file)
continue
with open(file, 'w', encoding='utf-8') as file_obj:
file_obj.write(file_content)
python class中插入代码
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
相关阅读更多精彩内容
- Python小白 Leetcode刷题历程 No.31-No.35 下一个排列、最长有效括号、搜索旋转...
- 在撰写技术文章的时候,为了增加阅读的舒适性,需要在Word中插入语法高亮显示的Python代码段,具体步骤如下: ...
- 打开word文档,插入,对象,新建,OpenDocument文本,这里等待粘入代码。 在VS2017或者其他IDE...
- 打开word文档,插入,对象,新建,OpenDocument文本,这里等待粘入代码。 在VS2017或者其他IDE...
- Python小白 Leetcode刷题历程 No.56-No.60 合并区间、插入区间、最后一个单词的...