Michael Hartl wrote:
I use a function isListLike in cases such as this one:

# def isListLike(L):
#     """Return True if L is list-like, False otherwise."""
#     try:
#         L + []
#         return True
#     except:
#         return False

Then you can use a standard if-else construct:

# if isListLike(myvar):
#     <do something>
# else:
#     <do something else>

What kind of situations do you use this for? I almost never have to do this kind of typechecking. If it's supposed to be a list, I just use it as a list...


STeVe
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to