Predefined (writable) attributes:$_{__name__}$ is the module’s name;$_{__doc__}$ is the module’s documentation string, or None if unavailable; __annotations__ (optional) is a dictionary containing variable annotations collected during module body execution;$_{__file__}$ is the pathname of the file from which the module was loaded, if it was loaded from a file. The$_{__file__}$ attribute may be missing for certain types of modules, such as C modules that are statically linked into the interpreter; for extension modules loaded dynamically from a shared library, it is the pathname of the shared library file. 

Special read-only attribute: __dict__ is the module’s namespace as a dictionary object. 

CPython implementation detail: Because of the way CPython clears module dictionaries, the module dic- tionary will be cleared when the module falls out of scope even if the dictionary still has live references. To avoid this, copy the dictionary or keep the module around while using its dictionary directly. 

Custom classes Custom class types are typically created by class definitions (see section Class definitions ). A class has a namespace implemented by a dictionary object. Class attribute references are translated to lookups in this dictionary, e.g., C.x is translated to C.__dict__["x"] (although there are a number of hooks which allow for other means of locating attributes). When the attribute name is not found there, the attribute search continues in the base classes. This search of the base classes uses the C3 method resolution order which behaves correctly even in the presence of ‘diamond’ inheritance structures where there are multiple inheritance paths leading back to a common ancestor. Additional details on the C3 MRO used by Python can be found in the documentation accompanying the 2.3 release at https://www.python.org/download/releases/2.3/mro/. 

When a class attribute reference (for class C , say) would yield a class method object, it is transformed into an instance method object whose$_{__self__}$ attribute is$_{C}$. When it would yield a static method object, it is trans- formed into the object wrapped by the static method object. See section Implementing Descriptors for another way in which attributes retrieved from a class may differ from those actually contained in its$_{__dict__}$ . 

Class attribute assignments update the class’s dictionary, never the dictionary of a base class. 

A class object can be called (see above) to yield a class instance (see below). 

Special attributes: __name__ is the class name;$_{__module__}$ is the module name in which the class was defined;$_{__dict__}$ is the dictionary containing the class’s namespace;$_{__bases__}$ is a tuple containing the base classes, in the order of their occurrence in the base class list;$_{__doc__}$ is the class’s documentation string, or$_{None}$ if undefined;$_{__annotations__}$ (optional) is a dictionary containing variable annotations collected during class body execution. 

Class instances A class instance is created by calling a class object (see above). A class instance has a namespace implemented as a dictionary which is the first place in which attribute references are searched. When an attribute is not found there, and the instance’s class has an attribute by that name, the search continues with the class attributes. If a class attribute is found that is a user-defined function object, it is transformed into an instance method object whose$_{__self__}$ attribute is the instance. Static method and class method objects are also transformed; see above under “Classes”. See section Implementing Descriptors for another way in which attributes of a class retrieved via its instances may differ from the objects actually stored in the class’s __dict__ . If no class attribute is found, and the object’s class has a$_{__getattr__()}$ method, that is called to satisfy the lookup. 

Attribute assignments and deletions update the instance’s dictionary, never a class’s dictionary. If the class has a$_{__setattr__()}$ or$_{__delattr__()}$ method, this is called instead of updating the instance dictionary directly. 

Class instances can pretend to be numbers, sequences, or mappings if they have methods with certain special names. See section Special method names . 

Special attributes:$_{__dict__}$ is the attribute dictionary;$_{__class__}$ is the instance’s class. 

I/O objects (also known as file objects) A file object represents an open file. Various shortcuts are available to create file objects: the open() built-in function, and also os.popen() , os.fdopen() , and the makefile() method of socket objects (and perhaps by other functions or methods provided by extension modules). 

The objects$_{sys.stdin}$ ,$_{sys.stdout}$ and$_{sys.stderr}$are initialized to file objects corresponding to the interpreter’s standard input, output and error streams; they are all open in text mode and therefore follow the interface defined by the$_{io.TextIOBase}$ abstract class. 

