Next: Classes and Class Instances Prev: Other Built-in Types Up: Other Built-in Types Top: Top

2.1.7.1. Modules.

The only special operation on a module is attribute access: m.name, where m is a module and name accesses a name defined in m's symbol table. Module attributes can be assigned to. (Note that the import statement is not, strictly spoken, an operation on a module object; import foo does not require a module object named foo to exist, rather it requires an (external) definition for a module named foo somewhere.)

A special member of every module is __dict__. This is the dictionary containing the module's symbol table. Modifying this dictionary will actually change the module's symbol table, but direct assignment to the __dict__ attribute is not possible (i.e., you can write m.__dict__['a'] = 1, which defines m.a to be 1, but you can't write m.__dict__ = {}.

Modules are written like this: <module 'sys'>.