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
I
was 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.
Get Python Pocket Reference, 4th Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.