Current situation:
def isTooLarge(intValue):
if intValue > 100: print "too large"; return True
return False
if isTooLarge(101): break
Now I like to make the function more "library-friendly" by returning the errormessagetext instead of printing it:
def isTooLarge(intValue):
if intValue > 100: return True, "too large"
return False
bln,str = isTooLarge(101)
if bln: specialprint(str); break
Any idea how I can evaluate it as an one-liner again? (something like "if ,str isTooLarge(101): specialprint(str); break" or what is the Python way here?
No problem to put the errormessage into a global variable like "lasterrormessage" and keep the rest as is.
if isTooLarge(101): print("too large"); breakjust let whatever callsisTooLargedeal with the error message/text.isTooLargetwice. But what you have written is probably the clearest way.isTooLarge(101)[0]. Caveat, I'm not a Python guy, so if it doesn't work, you've been warned. See stackoverflow.com/questions/431866/…raise ValueError("too large"). Then, the callie has to deal with it.