I am trying to be "Python-esque" in my code, where I am trying to call three functions, in succession, the second one only gets called if the first one doesn't produce a result, and the third one only if the first and second don't...
sky = "none"
while sky == "none":
sky = searchUnguided(inframe, skysearch, debug=debug)
sky = searchPQ(ad, skysearch, maxpq, debug=debug)
sky = searchAB(ad, maxpq, debug=debug)
break
Each of these functions searchUnguided, searchPQ and searchAB returns a value, which is none by default but can be changed to something else. It's these "something else" cases that I want to stop the while sky == "none" loop on. Yet, it doesn't work as I expect it to, and all three functions are called even when the first one returns something other than none.
Example of one function (have verified it returns non-none values as expected):
def searchUnguided(filename, skysearch, debug=False):
utdate = filename[1:9]
n = int(filename[11:15])
skyout = "none"
for ndiff in skysearch:
sn = n - ndiff
skyim = "N" + utdate + "S" + str(sn).zfill(4)
fskyim = os.path.join(rawdir, skyim + ".fits")
try:
sad = AD.read(fskyim, mode='readonly')
if getstate(sad, "frozen") != "none":
# we found a sky!
skyout = skyim
break
except:
continue
return skyout
Am I misunderstanding the way the while loop works? I can always use nested if statements but that seems so long-winded...
Thanks in advance!
breakit will run forever...