__package__ — Easy Examples
The name of the package a module belongs to
Accessing __package__
How to access and use __package__.
python
# __package__ print("Demonstrating __package__") print(type(object).__dict__.keys())
__package__ is a special attribute that the name of the package a module belongs to.
__package__ in practice
Using __package__ in everyday code.
python
# More __package__ examples print("__package__ 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 __package__ helps you introspect and debug Python objects.
Want to try these examples interactively?
Open Easy Playground