Objects¶
flutils offers the following object utility functions:
flutils.objutils.
has_any_attrs
(obj, *attrs)[source]¶Check if the given
obj
has ANY of the given*attrs
.
Parameters: Return type: Example
>>> from flutils.objutils import has_any_attrs >>> has_any_attrs(dict(),'get','keys','items','values','something') True
flutils.objutils.
has_any_callables
(obj, *attrs)[source]¶Check if the given
obj
has ANY of the givenattrs
and are callable.
Parameters: Return type: Example
>>> from flutils.objutils import has_any_callables >>> has_any_callables(dict(),'get','keys','items','values','foo') True
flutils.objutils.
has_attrs
(obj, *attrs)[source]¶Check if given
obj
has all the given*attrs
.
Parameters: Return type: Example
>>> from flutils.objutils import has_attrs >>> has_attrs(dict(),'get','keys','items','values') True
flutils.objutils.
has_callables
(obj, *attrs)[source]¶Check if given
obj
has all the givenattrs
and are callable.
Parameters: Return type: Example
>>> from flutils.objutils import has_callables >>> has_callables(dict(),'get','keys','items','values') True
flutils.objutils.
is_list_like
(obj)[source]¶Check that given
obj
acts like a list and is iterable.List-like objects are instances of:
List-like objects are NOT instances of:
None
bool
bytes
ChainMap
Counter
OrderedDict
UserDict
UserString
defaultdict
Decimal
dict
float
int
str
- etc…
Parameters: obj ( Any
) – The object to check.Return type: bool
Examples
>>> from flutils.objutils import is_list_like >>> is_list_like([1, 2, 3]) True >>> is_list_like(reversed([1, 2, 4])) True >>> is_list_like('hello') False >>> is_list_like(sorted('hello')) True
flutils.objutils.
is_subclass_of_any
(obj, *classes)[source]¶Check if the given
obj
is a subclass of any of the given*classes
.
Parameters: Return type: Example
>>> from flutils.objutils import is_subclass_of_any >>> from collections import ValuesView, KeysView, UserList >>> obj = dict(a=1, b=2) >>> is_subclass_of_any(obj.keys(),ValuesView,KeysView,UserList) True