0
首先:對我的英語感到抱歉!在其他Python腳本中識別循環
我想寫一個python腳本,可以識別其他python腳本中的任何循環。
import re
with open('boite_a_fonctions_v3_1.py', 'r') as f:
text=f.read()
a = text.split(" ")
#print (a)
loop = re.compile(r'for"(.*):\t(.*)"')
def find_loop(a):
c = []
for line in a:
c += loop.findall(line)
print (c)
#find_loop(a)
我沒有結果(這已經讓我開心,沒有錯誤!!)。任何人有任何建議?
代碼「boite_a_fonctions_v3_1.py」的一部分:
fidr.seek(0)
reg = compile(fmt.get_motif())
id = 0
for line in fidr :
for seg in reg.findall(line) :
if id == tokenId :
mot, etq = seg
return mot, etq
else :
id += 1
return None
def get_tokens(fid, fmt, tokenIds):
if isinstance(tokenIds, int):
try :
return get_token(fid,fmt, tokenIds)
except :
return None
else:
n = None
for id in tokenIds:
try:
n = len(get_token(fid,fmt, id))
break
except:
pass
if not n :
return None
ret = list()
for i in range(n) :
tmp = list()
for id in tokenIds :
try:
tmp.append(get_token(fid,fmt,id)[i])
except:
pass
ret.append(tmp)
return ret