Objects¶
flutils offers the following object utility functions:
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
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
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
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
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:
etc…
- Parameters
obj (
Any
) – The object to check.- Return type
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
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