import osimport re
from bi.models.permission import permissions
import re
#得到當前路徑
abspath=os.getcwd()
#遍歷當前路徑目錄下的所有*py檔案
def get_allfile(path):
result =
for maindir, subdir, file_name_list in os.walk(path):
# print('當前主目錄')
# print(maindir)
# print('當前主目錄下的所有目錄')
# print(subdir)
# print('當前主目錄下的所有檔案')
# print(file_name_list)
for filename in file_name_list:
if os.path.splitext(filename)[1]=='.py':
# print(os.path.splitext(filename)[1])
apath = os.path .join(maindir, filename) # 合併成乙個完整路徑
return result
all_routes=
routes=getblueprint(path)
if routes:
all_routes.extend(routes)
return all_routes
def getblueprint(path):
with open(path, 'r', encoding='utf8') as file_object:
text = file_object.read()
ss = r'''=(.*)blueprint\(\'(.*)\'(.*)__name__\)'''
pattern = re.compile(ss)
res = re.search(pattern, text)
if res:
blue=res.group(2)
ss = '@' + blue + r'''.route\(\'''' + r'(.*)' + r'\'(.*)' + r'methods=\[\'(get|post)\'\]\)'
res = re.findall(ss, text)
if res:
routes =
for i in res:
# print(routes)
return routes
filelist=get_allfile(abspath)
# print(allroutes)
text=str(allroutes)
# print(text)
routedict=
for i,j in routedict.items():
# print(i)
# print(j)
text = re.sub(r"[^_]"+i, j, text)
# print(allroutes)
text = re.sub('group','分組', text)
# print(text)
text=text.replace('/',' ')
text=text.replace("'",' ')
text=text.replace("[",' ')
maplist=text.split(',')
print(allroutes)
print(maplist)
print(len(allroutes)==len(maplist))
獲取Django所有路由
直接上 from django.urls import regexurlpattern defget all urls patterns,pre fix,is firt time false,result if is firt time result.clear for item in patter...
jqGrid載入並獲取所有行資料,遍歷所有行資料
1 jqgrid載入並獲取所有行資料 獲取當前 的所有資料 function getjqalldata trigger reloadgrid var rows obj.jqgrid getrowdata 此時獲取 所有匹配的 obj.jqgrid setgridparam trigger reloa...
遍歷html中所有DOM節點,並計算DOM節點數
這是乙個我在面試中遇到的問題,之前從來沒有想過這個問題,所以一被問就卡住了,當然結果也就是涼涼了 所以下來查了一下這個問題,並做以記錄警戒自己 定義乙個空陣列,存放或者取出製表位 t var blanks 遍歷的函式主體 function getchildren parent blanks.pop ...