mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-05-07 22:02:50 +00:00
Add is_iterable utility function
This commit is contained in:
committed by
Sviatoslav Sydorenko
parent
e6eec79bca
commit
6cafa73441
@@ -15,6 +15,18 @@ def is_string(seq):
|
||||
return isinstance(seq, (text_type, binary_type))
|
||||
|
||||
|
||||
def is_iterable(seq, include_strings=False):
|
||||
"""Identify whether the input is an iterable."""
|
||||
if not include_strings and is_string(seq):
|
||||
return False
|
||||
|
||||
try:
|
||||
iter(seq)
|
||||
return True
|
||||
except TypeError:
|
||||
return False
|
||||
|
||||
|
||||
def is_sequence(seq, include_strings=False):
|
||||
"""Identify whether the input is a sequence.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user