How to test for type or instance of dict_values?
Peter Otten
__peter__ at web.de
Thu Nov 17 07:38:26 EST 2016
Thorsten Kampe wrote:
> How can I test for type or instance of dictviews like dict_values?
Why do you want to?
> `isinstance({}.values, dict_values)` gives
> `NameError: name 'dict_values' is not defined`
You can "fix" this with
>>> dict_values = type({}.values())
or, depending on the use case, use another test:
>>> isinstance({}.values(), collections.abc.ValuesView)
True
> """
>>>> type({}.values())
> <class 'dict_values'>
> """
>
> Thorsten
More information about the Python-list
mailing list