mardi 3 février 2015

python search function not working


I need help with part of python code. I have search function which will search for string in file, and retrun it if found, or give Error dialog if not found. Also after Error dialog is closed, give user right to enter correct value. I did't put whole code, but basicly /tmp/ARNE/final1 file looks like:



siu43543, RTWAURT
siu34544, RYAKCCD


and if user enters name for example siu43543, it will reaturn RTWAURT, or give error dialog, and wait for correct value. So my function needs to give error dialog, or the value, if found.



def search(VAR,VAR1):
global linese
global linese1
with open("/tmp/ARNE/final1", 'r') as file:
for line in file:
var=re.search(VAR, line)
if var:
linese = line.split(',')[0]
else:
tkMessageBox.showinfo("ERROR", "MISSING ELEMENT")
return Exception

var11=re.search(VAR1, line)
if var1:
linese1 = line.split(',')[1]
else:
tkMessageBox.showinfo("ERROR", "MISSING PARENT")
return Exception
return linese
return linese1

try:
search(line1,line1)
except Exception:
break


Aucun commentaire:

Enregistrer un commentaire