day21 study notes

A python file has two purposes: 1. to be run as a program

2. The module is imported as a
difference between the two: ps (recovery) __ name __ == main
Import Import module must be prefixed by "module." When using the
advantages: certainly not with the current name space conflict
Cons: seems trouble
from module name import function name (function name in the global variable is the current position, but at the memory address is the memory address of the module)
when introduced in this way three things happen:
1. generate a module namespace

2. The name of the runtime generated are thrown into the namespace of the module to

3. get a name in the current namespace, the name and address of a particular memory module namespace bindings
advantages: streamlined
Disadvantages: will the current namespace and confusion
can also import multiple line name
from the name of the module can import * All names time import module (not recommended)
Learn __all__ = [ "module name"] * will come when introduced according to the method of this property module
as alias can be used to
cycle the introduction: two modules occurs guide with each other, a common approach should be placed in a single module, or the import process on the internal method
module search path priority: whether it is import or re-import the module from all involved is to find the problem
priority:
1. RAM

2. order sys.path file stored in order to find the file
under the sys module sys.path method to store a series of folders, the first of which is the current file folder where the executable file folder
understand: sys.modules view has been loaded memory modules
python itself provides an optimization mechanism, after the import module, the memory space will not open because there is no designated space or release function to release the class, there will always be aware of the program to complete
the application of sys.path : cross-file import module, you can use the list sys.path like to add the path to complete the
module format specification: document description module

Import module

Define global variables

The definition of class

Defined Functions

Main
supplementary function type Note: is the minimum version required python3.5
DEF FUNC (A: 'from spam', B: (. 1, 10), C: a float) -> int:
return A + B + C
DEF FUNC (A: 'from spam' =. 4, B: (. 1, 10) =. 5, C: = a float. 6) -> int:
return a + B + C
strongly typed languages (Python are strong type): the data type can not be ignored language i.e., the data type of the variable being defined once, it will not change, unless strong rotation. In python, for example: name =
'XXX', the variable name in the moment of the assignment, the data type was determined died
a weakly typed language: data types can be ignored language such as linux in the shell define a variable, with the invocation of a different data type can easily switch the kind of
dynamic languages (python is the dynamic language)
data type checking that is only running at variable assignment, it determines the data type of the variable, without prior to the specified variable data type
static languages
require prior to the variable data type definitions
in summary, Python is a strongly typed language dynamic interpreted
what package: is a folder that contains the __init__.py
Note: 1. in the python3 even if there is no next package __init__.py file, import the package is still not being given, but in python2, the next package must have the file, or import the package error
2. create the package was not intended to run, but be imported using , remember, only one form of package module only, the nature of the package is a kind of mold
Import package three-step process: 1, __init__.py file under the Execute Package
2, resulting in the name of a new name for the storage space produced in the implementation process __init__.py
3, where the executable file in the current namespace get a name, the name of the point __init__.py namespace
absolute import: to package this as a starting import folder
on environmental variables in the program's executable file is subject to all of the modules are imported or subsequent other documents cited reference path is subject to execution of a file
1. import-related statements about the package is also divided into import and from ... import ... are two, but no matter what, no matter what position, when importing We must follow a principle: whatever little when importing the left point must be a package, otherwise illegal. It may have a series of points, such as import top-level package. Subpackages. Sub-modules, but must follow this principle. But after the introduction, when using no such limit, the package may be left point, modules, functions, classes (which can be called its own properties manner points).

2, the package has the same name as the module does not conflict the packages A and B, as Aa and Ba from two namespaces

3, when the import file import, generate namespace name from file, import the package, the name of the name space generated from the same document, i.e. __init__.py the packet, the packet is essentially introduced in the import file

Relative Import: Represents the directory of the current file, representing the current directory .. the parent directory, and so on
relative imports can only be used from module import symbol of the form, import ..versions grammar is wrong, and the only symbol is a clear name
for each import is recommended between the relative import module inside the package, it needs to be emphasized:
1, relative to import only package internal use, with modules in different directories relative imports is illegal
2, either import or from-import, but all a little at the time of import, the left point must be a package or a syntax error

Guess you like

Origin www.cnblogs.com/Jicc-J/p/12593323.html
Recommended