在自己的用户路径下C:\Users\ALG\AppData\Roaming\Sublime Text\Packages\User建立文件remove_comments.py:
pythonimport sublime_plugin
import sublime
class RemoveCommentsCommand(sublime_plugin.TextCommand):
def run(self, edit):
comments = self.view.find_by_selector('comment')
for region in reversed(comments):
self.view.erase(edit, region)
这里的默认路径就是刚才的路径:
使用 ctrl+` 打开sublime命令行:
shellview.run_command('remove_comments')
修改这里:
config.py
pythonimport os
jklp = r"D:\Desktop\AI算法库-吸烟检测算法V1.2"
algname = os.path.basename(jklp)
执行这里:
huihui1.py
pythonimport os
import re
from config import *
def all_path(dirname):
result = []
for maindir, subdir, file_name_list in os.walk(dirname):
for filename in file_name_list:
apath = os.path.join(maindir, filename)
result.append(apath)
return result
path = jklp
result = []
for name in all_path(path):
name1 = os.path.join(path, name)
if name1.endswith(".py"):
try:
singleTxt = open(name1, "r", encoding="utf-8").readlines()
if len(singleTxt) > 10:
result.extend("\nprint(wqeqweuiqdbkasbd1231241241241241)\n")
result.append(f"\nprint qqqqqqqqqqqqqqqqqqqqqqqqqqqq {os.path.basename(name)}\n")
result.extend(singleTxt)
except:
pass
open("result.py", "w", encoding='utf-8').writelines(result)
使用 sublime删除注释后再使用这里:
huihui2.py
pythonimport os
import re
from config import *
Txt = open(r"D:\Desktop\result.py", "r", encoding="utf-8").read()
Txt = Txt.replace("print qqqqqqqqqqqqqqqqqqqqqqqqqqqq", "#")
Txt = Txt.replace("print(wqeqweuiqdbkasbd1231241241241241)", f'"""\nCopyright 2017-2022 ------ Inc \n{algname} \n"""')
open("result1.py", "w", encoding='utf-8').write(Txt)
import os
import re
Txt = open("result1.py", "r", encoding="utf-8").readlines()
Txt = list(filter(lambda x: len(x) > 2, Txt))
# os.remove("result2.py")
open(f"{algname}.py", "w", encoding='utf-8').writelines(Txt)
本文作者:Dong
本文链接:
版权声明:本博客所有文章除特别声明外,均采用 CC BY-NC。本作品采用《知识共享署名-非商业性使用 4.0 国际许可协议》进行许可。您可以在非商业用途下自由转载和修改,但必须注明出处并提供原作者链接。 许可协议。转载请注明出处!