I am trying to write a python script that can reconher any boucle for in other python scripts.
import re
with open('boite_a_fonctions_v3_1.py', 'r') as f:
text=f.read()
a = text.split(" ")
#print (a)
boucle = re.compile(r'for"(.*):\t(.*)"')
def recherche_boucle(a):
c = []
for linha in a:
c += boucle.findall(linha)
print (c)
#recherche_boucle (a)
I have nothing as a result (which already makes me happy, at least there are no mistakes !!). Anyone have any suggestions?
Ah, a part of the code 'boite_a_fonctions_v3_1.py':
fidr.seek(0)
reg = compile(fmt.get_motif())
id = 0
for line in fidr :
# par ligne
for seg in reg.findall(line) :
# par token
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