We can import Container
in two ways:
from collections import Container
from collections.abc import Container
help
function for both Container
returns the same documentation.
help(collections.Container)
:
Help on class Container in module collections.abc:
class Container(builtins.object)
| Methods defined here:
|
| __contains__(self, x)
|
| ----------------------------------------------------------------------
| Class methods defined here:
|
| __subclasshook__(C) from abc.ABCMeta
| Abstract classes can override this to customize issubclass().
|
| This is invoked early on by abc.ABCMeta.__subclasscheck__().
| It should return True, False or NotImplemented. If it returns
| NotImplemented, the normal algorithm is used. Otherwise, it
| overrides the normal algorithm (and the outcome is cached).
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __abstractmethods__ = frozenset({'__contains__'})
help(collections.abc.Container)
:
Help on class Container in module collections.abc:
class Container(builtins.object)
| Methods defined here:
|
| __contains__(self, x)
|
| ----------------------------------------------------------------------
| Class methods defined here:
|
| __subclasshook__(C) from abc.ABCMeta
| Abstract classes can override this to customize issubclass().
|
| This is invoked early on by abc.ABCMeta.__subclasscheck__().
| It should return True, False or NotImplemented. If it returns
| NotImplemented, the normal algorithm is used. Otherwise, it
| overrides the normal algorithm (and the outcome is cached).
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __abstractmethods__ = frozenset({'__contains__'})
What is the difference between these two imports? Why are we allowed to do both?
Update
Got deprecation warning while importing Container
from collections
(Python 3.7.3
).
From Python 3.8
it cannot be imported directly from collections
.
>>> from collections import Container
main:1: DeprecationWarning: Using or importing the ABCs from 'collections' instead of from 'collections.abc' is deprecated, and in 3.8 it will stop working