With isinstance
we can check whether something is of a certain type, but how can we test whether an object is a class belonging to a certain module?
Example:
>>> type(root)
<class 'bs4.BeautifulSoup'>
>>> isinstance(root, BeautifulSoup)
True
How to test whether this object "belongs" to the bs4 package?
Note: When I go over the objects in the soup recursively, it starts as a bs4.BeautifulSoup
object, but at another level they are bs4.element.Tag
nodes. This is why I want to check for originating from this module rather than a particular type.