Last active
July 4, 2020 15:50
-
-
Save jss367/d63f446a0db19d17f345810b579ffe6b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Sometimes I make functions that can either allow an object or a list of objects. | |
# To do this I check if an input is an object and, if so, wrap it in a list. | |
# Here's a simple way to do that. | |
def _isArrayLike(obj): | |
return hasattr(obj, '__iter__') and hasattr(obj, '__len__') | |
objs = objs if _isArrayLike(objs) else [objs] | |
#Another option is to do the opposite check: | |
if isinstance(obj, ObjType): | |
obj = [obj] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment