How to return an "not string' error in function?
Cameron Laird
claird at lairds.us
Thu Sep 21 11:34:31 EDT 2006
In article <1158848968.493858.96600 at k70g2000cwa.googlegroups.com>,
<breakfastea at gmail.com> wrote:
>Thank you so much it answers my humble question perfectly:)
>
HOWEVER, to answer you final question, yes, there is a different
and, in general, better, way. While there's a lot to say about
good Python style and typing, I'll summarize at a high level:
you shouldn't have to check types. I can understand that you
are working to make a particular function particularly robust,
and are trying to account for a wide range of inputs. This is
healthy. In stylish Python, though, you generally don't need
type checking. How would it be, for example, if someone passed
the number 3 to your function. Is that an error? Do you want
it automatically interpreted as the string "3"? You can achieve
these results withOUT a sequence of
if isinstance(...
elif isinstance(...
...
perhaps with something as simple as
my_input = str(my_input).
One of us will probably follow-up with a reference to a more
detailed write-up of the subject.
More information about the Python-list
mailing list