As best I understand, a function call terminates (i.e., no further code is executed within the function) once the function returns. I want to test an if statement and return a value if it is true, and then immediately exit the function without executing additional code in the function. However, my log output shows that I am entering the if, returning, and then continuing to execute code following the if block in the function. How do I exit the function once the return statement associated with left lane is encountered?
def insanity(self, pts_y, pts_x, lane='left'):
# no pts detected, return saved points from instance
if (len(pts_y) == 0 or len(pts_x) == 0):
if lane is 'left':
self.logger.warning('Sanity Check: left should be returning')
return self.lefty_p, self.leftx_p # return saved instance value
elif lane is 'right':
self.logger.warning('Sanity Check:right should be returning')
return line_fit, self.righty_p, self.rightx_p # return saved instance value
else: self.logger.warning('Sanity Check: Did not properly return buffered points')
self.logger.warning('Should not be getting passed if')
Log Output:
WARNING - Sanity Check: left should be returning
WARNING - Should not be getting passed if
Aucun commentaire:
Enregistrer un commentaire