Tweaked docstrings.

This commit is contained in:
Donne Martin 2015-01-24 07:08:07 -05:00
parent 0510eb997c
commit 595ab2358b

View File

@ -2,6 +2,12 @@ class Util:
@classmethod
def is_iterable(self, obj):
"""Determines if obj is iterable.
Useful when writing functions that can accept multiple types of
input (list, tuple, ndarray, iterator). Pairs well with
convert_to_list.
"""
try:
iter(obj)
return True
@ -10,9 +16,8 @@ class Util:
@classmethod
def convert_to_list(self, obj):
"""Useful when writing functions that can accept multiple types of
input (list, tuple, ndarray, iterator). Checks if the object is a list.
If it is not a list, converts it to a list.
"""Converts obj to a list if it is not a list and it is iterable, else
returns the original obj.
"""
if not isinstance(obj, list) and self.is_iterable(obj):
obj = list(obj)