import md # module name is md.py but when the introduced just write md, can not file suffix
Operation is equivalent to taking md.py code file, and the point md.py into executable file namespace namespace
Once you run this run.py file, first of all he created run.py namespace
First import module (Import Module three stages) (md.py) ( ** ),
1: Perform md.py file
2: Run md.py code in the file name will generate and store a value to md.py namespace
3: generating a pointer to the namespace name (md) in the executable file
Multiple imports will not execute module file will follow the outcome of the first import ( ** )
Call many times does not make sense, because you know python has been called this module
python memory space will determine the implementation of this document have not been imported namespace, if there is, python know you have imported a
Use import import module access module namespace name potential unified sentence: module name names.
Features include:
1. by name access module names will never conflict with the executable file name
2. If you want to access the module name must use the module name Name of way
supplement:
introducing a plurality of support modules import line, but not recommended, but as long as several modules belonging to the same part or with a module, this can be written
When the case is not linked to several modules should be divided into multiple imports:
import os
import time
Normally import modules sentence will be written in the beginning of the file
(There are exceptions: a specific function module used, do not call the function module is not performed, (in order to save memory space))
If the module name may be used as long an alias
import time as t
Money MD1 import from # from import module name to come up with the name
# Multiple imports will not be executed, it will follow the first import results
# Execute the code md1
First creates run1.py namespace
First import md1.py module
1. Run md1.py
2. The name of the store to generate md1.py namespace
3. Direct pointing md1.py get a value namespace name
Using from .. import .. sentence.
1. Access module name does not need to add the module name prefix
2. The name of the access module may access the current round of the executable file name conflicts (shortcomings)
supplement:
import * from module name
# Disposable md1 put all the names in the module are out (not recommended)
Because to take more would be more take up memory
# Principle: Find module in all things in:
If all I did not write, the default is all things,
If you write, then write a few can only take a few
* The reason why something can come out of all
all = []
# This should put the final surface, not otherwise defined name
# And the name should be written on the inside quotation marks, into a string type, separated by commas
all = ['read1','read2']
# Do not write all the names which by default