__path__ — Easy Examples
List of paths where a package's submodules can be found
Accessing __path__
How to access and use __path__.
python
# __path__ holds package search paths import os print(os.__path__ if hasattr(os, '__path__') else 'os has no __path__') import json print("json is a package" if hasattr(json, '__path__') else "json is a module")
__path__ is a special attribute that list of paths where a package's submodules can be found.
__path__ in practice
Using __path__ in everyday code.
python
# More __path__ examples print("__path__ is a special Python attribute") # Every object has certain dunder attributes obj = object() attrs = [a for a in dir(obj) if a.startswith("__")] print(f"object has {len(attrs)} dunder attributes")
Understanding __path__ helps you introspect and debug Python objects.
Want to try these examples interactively?
Open Easy Playground