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 in C’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.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset