como dizer uma variável é iterável, mas não uma string
Eu tenho uma função que leva um argumento que pode ser um único item ou um item duplo:
def iterable(arg)
if #arg is an iterable:
print "yes"
else:
print "no"
de modo a:
>>> iterable( ("f","f") ) yes >>> iterable( ["f","f"] ) yes >>> iterable("ff") no
O problema é que string é tecnicamente iterável, então eu não posso simplesmente pegar o ValueError ao tentararg[1]
. Eu não quero usar isinstance (), porque isso não é uma boa prática (ou assim me disseram).