Mod Pack
Mod Pack
Therefore, if you want to write a somewhat longer program, you are better
off using a text editor to prepare the input for the interpreter and running it
with that file as input instead.
As your program gets longer, you may want to split it into several files for
easier maintenance.
You may also want to use a handy function that you’ve written in several
programs without copying its definition into each program.
To support this, Python has a way to put definitions in a file and use them in a
script or in an interactive instance of the interpreter.
Such a file is called a module; definitions from a module can be imported into
other modules or into the main module (the collection of variables that you have
access to in a script executed at the top level and in calculator mode).
A module is a file containing Python definitions and statements. The file name is
the module name with the suffix .py appended.
Within a module, the module’s name (as a string) is available as the value of the
global variable __name__. For instance, use your favorite text editor to create a
file called fibo.py in the current directory with the following contents
Packages are a way of structuring Python’s module namespace by using “dotted module
names”.
For example, the module name A.B designates a submodule named B in a package named A.
Just like the use of modules saves the authors of different modules from having to worry
about each other’s global variable names, the use of dotted module names saves the authors
of multi-module packages like NumPy or Pillow from having to worry about each other’s
module names.
Suppose you have developed a very large application that includes many modules.
As the number of modules grows, it becomes difficult to keep track of them all if they are
dumped into one location.
This is particularly so if they have similar names or functionality. You might wish for a means
of grouping and organizing them.
Packages allow for a hierarchical structuring of the module namespace using dot notation.
In thsame way that modules help avoid collisions between global variable names,
packages help avoid collisions between module names.