Many times I want a function parameter that is an iterable but not a string. Usually I do:
try: var.__iter__ except AttributeError: # not an iterable else: try: var.isascii except AttributeError: # put yuour code here or from collections.abc import Iterable if isinstance(var, Iterable) and not isinstance(var, str): # put yuour code here The first example uses duck typing but it's more verbose. I use the first method in an home-made utility function. I think it could be interesting to add a syntactic sugar to do this. Maybe a collections.notTextIterable() collections.nonTextIterable() collections.notStrIterable() collections.iterableNotStr() ? _______________________________________________ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/P74I55RJX4S2FUEFI6PIIKVP64F2NQJR/ Code of Conduct: http://python.org/psf/codeofconduct/