Built-in Attributes
Some objects export special attributes that are predefined by Python. The following is a partial list because many types have unique attributes all their own; see the entries for specific types in the Python Library Reference.[6]
X.__dict__Dictionary used to store object
X’s writable attributes.I.__class__Class object from which instance
Iwas generated. In version 2.2 and later, this also applies to object types; most objects have a__class__attribute (e.g.,[].__class__==list==type([])).C.__bases__Tuple of class
C’s base classes, as listed inC’s class statement header.X.__name__Object
X’s name as a string; for classes, the name in the statement header; for modules, the name as used in imports, or"__main__"for the module at the top level of a program (e.g., the main file run to launch a program).
[6] As of Python 2.1, you can also attach arbitrary user-defined
attributes to function objects,
simply by assigning them values. Python 2.X also supports special
attributes I.__methods__ and
I.__members__: lists of method
and data member names for instances of some built-in types. These
are removed in Python 3; use the built-in dir() function.
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access