Problem: The function [self._oun(upsplit[.....] in the code given below returns either a word (string) or a bool(FALSE). Now when the concatenation through + operator happens, it tries to concatenate a bool (say FALSE) with a string and hence fails with an exception (TypeError, concatenating bool with str). It works perfectly fine when a string is returned.
How can I change the code in a pythonic way to handle the above problem? I just tried putting an if statement before this code to check for the return value and then have two else statements, one if the returned value is bool and one with string (which does not look pythonic to me).
return ' '.join(upsplit[:word-1] +
[self._oun(upsplit[word-1], 1) +
'-' + upsplit[word] + '-']) + \
' '.join(upsplit[(word+1):])
EDIT:
If it returns FALSE I just want to append it with upsplit[word] and not the return value (which would be bool FALSE). Note that the function does not return TRUE. It either returns a modified string or it returns FALSE. If it returns FALSE than I just need to append the original string stored in upsplit[word].
upsplititself. In python, returning an error code is an antipattern, the function should either return something meaningful or throw an exception.