code unable to reach else statement in elif in python -
else condition not executing .i unable print data after else statement. getting output resp=[] instead of resp[0]=-1
why getting ?is there mistake in code::
consider following code snippet
import os import re import time import sys import random res="received commandceptfrfg45g45g54g54hg \ received comtvtv56g56gh65ghbtg56hg3g5ty7u6y45g4 vreceived comrce_vrff \ rece mcmprepmoinreceivedcommanapcdcdcdcreceived commanp" def checkit(val): resp=[] test_comment=[] if val=='0x01': print "reached condition" if re.search("received command fcvdfc:",res): resp.append(0) elif(val=='0x02'): #if re.search("received",res): resp.append(0) elif(val=='0x03'): if re.search("received command wedwedewd:",res): resp.append(0) elif(val=='0x04'): if re.search("receive 1",res): resp.append(0) elif(val=='0x05'): if re.search("receiv2",res): resp.append(0) elif(val=='0x06'): if re.search("recei2",res): resp.append(0) elif(val=='0x07'): if re.search("received2 co",res): resp.append(0) elif(val=='0x08'): if re.search("receiv3",res): resp.append(0) elif(val=='0x09'): if re.search("received7",res): resp.append(0) elif(val=='0x0a'): print "reached condition" if re.search("received8",res): resp.append(0) elif(val=='0x0b'): print "reached condition" if re.search("received8",res): resp.append(0) elif(val=='0x0c'): print "reached condition" if re.search("receivedt9",res): resp.append(0) elif(val=='0x0d'): print "reached condition" if re.search("fwefef",res): resp.append(0) else: print "reached else condition" resp.append(-1) #return test_comment.append(str(res)) resp.append(test_comment) #print test_comment return resp li=['0x01','0x02','0x03','0x04','0x05','0x06','0x07','0x08','0x09','0x0a','0x0b','0x0c','0x0d']; in range(10): val=random.choice(li) print val ret=checkit(val); print "response:",ret,"\n"
checkit("0x00") # makes else branch executed
Comments
Post a Comment