On Fri, Aug 14, 2020 at 6:46 PM Marco Sulla
<marco.sulla.pyt...@gmail.com> wrote:
>
> Many times I want a function parameter that is an iterable but not a
> string.
> from collections.abc import Iterable
>
> if isinstance(var, Iterable) and not isinstance(var, str):
>     # put yuour code here
>

Well, that line of code asks if something is an iterable and not a
string. It perfectly captures the intent described in your opening
statement. I'd say go with it.

IMO the collections module isn't really right for something like that,
but if you really need a helper function for this one-liner, then I'd
say having one in your own code is perfectly reasonable.

ChrisA
_______________________________________________
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/7J2IZDWKQQ2OOVVDTLGNLO67SQOLQEFU/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to