I am wondering, is there a way that i can store start and end values on my main method. I try doing this but it give me error:
def searchM():
fileAddress = '/database/pro/data/'+ID+'.txt'
with open(fileAddress,'rb') as f:
root = etree.parse(f)
for lcn in root.xpath("/protein/match[@dbname='M']/lcn")
start = int(lcn.get("start"))#if it is PFAM then look for start value
end = int(lcn.get("end"))#if it is PFAM then also look for end value
return "%s, %s" % (start, end,)
values = searchM()
(start, end,) = values
The error message is UnboundLocalError: local variable ‘start’ referenced before assignment
The error you’re encountering is due to the
startandendvariables. Try initializing them first so that they exist in the even that a value is not set.In addition, you are trying to create and return a string, which is then unpacked into two different variables.
Try the following: