Review

  1. Modules
    1. A module is a single namespace with many possible values (functions, classes, constants, etc.)
    2. Usually corresponds to a file.
    3. All modules have a name.
    4. Python has only one type of module object.
  2. A Package is just a module that may contain other modules (or packages).
    1. It is module with a path attribute.
    2. Packages organize modules into a named hierarchy.
    3. Packages : modules :: directories : files
    4. Usually corresponds to a directory with with an init.py file in it.
  3. There are two kinds of packages (as of 3.3)
    1. Regular packages are traditional (2 and up to 3.2), they are a directory with an init.py file. They are dependent on the file system.
    2. Namespace packages are composed of portions. They do not have an init.py file. Portions can be anywhere. They are not dependent on the file system. They may be virtual.
  4. Import statements bring modules into modules. Combines two operations:
    1. Searches for named module.
    2. Binds results to local name, i.e. the fully qualified path or an alias.
    3. Compiles and runs the files and packages it imports.
  5. Some general ideas
    1. You can think of a module as a supplemental file relative to a top-level program or script.
    2. Module files generally don’t do anything when run directly – they are used by other files.
    3. When modules are imported, their elements are called attributes
    4. Imports execute init.py files from the context of the directory of execution. Think of this as the project directory.
    5. File and directory names should follow variable and function naming conventions since they will be used to create the names used in the importing program.
    6. Global scope is always the file enclosing it, regardless of which module it is ultimately called from.