Python Introspection and Class Attributes
PCAP objective 4.4 is discover the class structure, and it is a list of things you can ask an object about itself: __class__, __name__, __bases__, __mro__, __dict__, __doc__, plus isinstance, issubclass and the four *attr functions. Most of it is mechanical. Two details are not: type() and isinstance() disagree once inheritance is involved, and __doc__ is not inherited.
Object-Oriented Python Guide 17 of 25 Intermediate
- OSUbuntu 26.04 LTS
- Python3.14.4
- pip25.1.1
- TimeAbout 16 min
__mro__ and __bases__ are unchanged in Python 3. Every class has them, because every class is a new-style class - see guide 19.
| Server Name | IP Address | OS | Roles | CPU | RAM | HDD |
|---|---|---|---|---|---|---|
| RUNNER01 | 192.168.0.27 | Ubuntu 26.04 LTS | Python 3.14.4 - the only machine this path needs | 2 Core | 4 GB | 50 GB |
This guide includes
Use this for the class-discovery objective, which is a list of things to know rather than a concept. This matters because __doc__ is the one attribute that is not inherited, and that is exactly what gets asked.
- asking an object what it is, with six dunder attributes
- finding that
__doc__is not inherited when almost everything else is - reading the two dictionaries, on the instance and on its class
- using
isinstanceandissubclass - using the four attribute functions, and
diron a class of your own
Before you start
-
Asking an object what it is
-
__doc__ is not inherited
-
The two dictionaries
-
isinstance and issubclass
-
The four attribute functions
-
dir on your own class
-
What the exam does with this objective