Computer Science Chapter 11(Z)
Evaluating an import statement initiates the following process to load the module:
1) A check is conducted to determine whether the module has already been imported. If already imported, then the loaded module is used. 2) If not already imported, a new module object is created and inserted in sys.modules 3) The code in the module is executed in the new module object's namespace.
What directories are initially contained in the sys.path variable?
1) The directory of the executing script 2) A list of directories specified by the environmental variable PYTHONPATH 3) The directory where Python is installed (typically C:\Python27 or similar on Windows)
Module Object
A <this> is simply a namespace that contains definitions from the module. If the module has already been loaded, then the existing <this> is used
Hashlib Module
A Python standard library module that contains a number of algorithms for creating a secure hash of a text message. A secure hash correlates exactly to a single series of characters
Dependency
A module being required by another program is often called a <this>
Built-In Modules
A module that comes pre-installed with Python; examples of <these> include sys, time, and math
Module
A programmer may find themselves writing the same function over and over again in multiple scripts, or creating very long and difficult to maintain scripts. A solution is to use a <this>, which is a file containing Python code that can be imported and used by scripts, other <these>, or the interactive interpreter A <this>'s filename should end with ".py"; otherwise, the interpreter will not be able to import it The <this>_name item should match the filename of the <this>, but without the .py extension
Environmental Variable
An operating system <this> is much like a variable in a Python script, except that an <this> is stored by the computer's operating system and can be accessed by every program running on the computer
PYTHONPATH
For simple programs, a module might simply be placed in the same directory. Larger projects might contain tens or hundreds of modules, or use third-party modules located in different directories. In such cases, a programmer might set the environmental variable <this> in the operating system
sys.path
Importing a module begins a search to find the corresponding file on the computer's file system. The interpreter first checks for a matching built-in module. A built-in module is a module that comes pre-installed with Python; examples of built-in modules include sys, time, and math. If no matching built-in module is found, then the interpreter searches the list of directories contained by <this>, located in the sys module
Script
The interactive Python interpreter provides the most basic way to execute Python code. However, all of the defined variables, functions, classes, etc., are lost when a programmer closes the interpreter. Thus, a programmer will typically write Python code in a file, and then pass that file as input to the interpreter. Such a file is called a <this>
Import
To <this> a module means to execute the code contained by the module, and make the definitions within that module available for use by the importing program
sys.modules
When importing a module, the interpreter first checks to see if that module has already been imported. A dictionary of the loaded modules is stored in <this> (available from the sys standard library module)
Write a statement that changes the output to use '$' when drawing shapes. (Change the value of shapes.cr).
shapes.cr = "$"