Hangzhou has ever been

Surrogacy is located in Hangzhou, a professional surrogate agency center, add a formal surrogacy Hangzhou: ██╇ micro-channel: 138 ★ 0226 ★ 9370╇██ mainly engaged in Hangzhou surrogate agency and surrogacy services and care, Hangzhou reasonable behalf maternal child price and strict the surrogacy process.

First, what is the package?

Is a file with an internal package __init__.py clip, may also be introduced into the package, and may be introduced together with all modules in the package.

Second, why should use the package?

The nature of the package is a folder, the folder only function is to organize files.
With the function write more and more, we can not all functions into a single file, so we use the module to organize functions, but as more and more modules, we need to use folders to organize files module to this structural and to improve the maintainability of the program.
There is a __init__.py in a package, which it has to help us manage module.

Third, how to use the package?

  1. import package. module name
  2. from package import module name
  3. from the package. import module module name names

Import what happens when the package:

  1. When the packet is introduced, __init__.py performs packet, generates a name space.
  2. All names will be added to the __init__.py in the name space.
  3. Then the names of the package will be loaded to all modules namespace __init__.py generated.
  4. Import module namespace pointing __init__.py is actually the name of the space created.

He stressed :
  In python3, even if there is no package __init__.py file, import the package is still not being given, but in python2, the package must be inside the file, or import the package error

Module

First, what is a module?

Module is a collection of a series of functional code.
In Python, a .py file is a module, the module file named xxx.py name is xxx, import module can refer to the function module has been written

- 模块的三种来源:
    1.python内置的模块: (python解释器的)
        比如: sys\time\os\turtle

    2.第三方的模块: (别人写的)
        比如: requests

    3.程序员自定义的模块: (自己写的)
        比如: 自己定义的demo.py文件
- 模块的四种表现形式:
    1.使用python编写的py文件。(了解)
    2.编译后的共享库DLL或者是C或者C++库。(了解)
    3.包下面带有__init__.py的一组py文件。
        - 包
            - __init__.py
            - demo.py
            - demo2.py
    4.python解释器下的py文件。
        - python解释器下的文件夹
           - 一个个的py文件

Second, why should use the module?

  • Module can help us better manage the function codes, such as: function ...
  • May be split into a number of functional items, are stored in different files py (module) of.

    Third, how to create, write module and use the module?

  • Right-click the file to create py
    - py write python code file

  • In a document by keyword import import module
    import module name
    Note: When you import the module, the module can not add the suffix .py
  • In using the module stage, it must be noted, who is the executable file, who is import the file (module to be introduced)

  • Module on the first import, imported modules has been loaded into memory, and then repeat the import will direct reference module already in memory, and will not repeat the file by import sys, you can see the value of print sys.modules already loaded into memory module name.
  • In the beginning of the file to import module belonging global scope, function module introduced in the local scope belong.

Module what happens when you import:

  1. It will first execute the currently executing file and generates the name of the currently executing file space.
  2. When executing the code module is introduced, is introduced into the module will produce a module namespace.
  3. Introduced into the module is loaded into memory namespace.
import foo      #导入模块foo
a=foo.x         #引用模块foo中变量x的值赋值给当前名称空间中的名字a
foo.get()       #调用模块foo的get函数
foo.change()    #调用模块foo中的change函数
  • To the module from the alias as
    Import module as an alias module

Fourth, the way of introducing the module

  • import module name
    - direct import import execution file

  • package from / import module name module name / (function name, variable name, class name)
    - directly in the executable file import Import

V. circulation import questions

    - m1.py
        print('正在导入m1')
        from m2 import y
        x='m1'

    - m2.py
        print('正在导入m2') from m1 import x - run.py import m1 #执行run.py会报错 - 解决循环导入问题: 1.需要查找的名字放在导入模块的上方 2.在函数内部导入,将模块加载到局部名称空间中

Six, py file distinguish two purposes: module and script

编写好的一个python文件可以有两种用途:
    一:脚本,一个文件就是整个程序,用来被执行
    二:模块,文件中存放着一堆功能,用来被导入使用
    
print(__name__)

__name__的值:

1、在文件被直接执行的情况下,等于'__main__'
2、在文件被导入的情况下,等于模块名

作用:用来控制.py文件在不同的应用场景下执行不同的逻辑

if __name__ =='__main__' func()

Seven, the module search path

Module search order :

  1. Memory modules that have been loaded
  2. Built-in module
  3. Module included in the path sys.path

Stressed : first path sys.path is currently executing the file folder where

import sys
print(sys.path)   

import sys
print(sys.modules)  #查找内存中存在的模块
 
Category:  Python

First, what is the package?

Is a file with an internal package __init__.py clip, may also be introduced into the package, and may be introduced together with all modules in the package.

Second, why should use the package?

The nature of the package is a folder, the folder only function is to organize files.
With the function write more and more, we can not all functions into a single file, so we use the module to organize functions, but as more and more modules, we need to use folders to organize files module to this structural and to improve the maintainability of the program.
There is a __init__.py in a package, which it has to help us manage module.

Third, how to use the package?

  1. import package. module name
  2. from package import module name
  3. from the package. import module module name names

Import what happens when the package:

  1. When the packet is introduced, __init__.py performs packet, generates a name space.
  2. All names will be added to the __init__.py in the name space.
  3. Then the names of the package will be loaded to all modules namespace __init__.py generated.
  4. Import module namespace pointing __init__.py is actually the name of the space created.

He stressed :
  In python3, even if there is no package __init__.py file, import the package is still not being given, but in python2, the package must be inside the file, or import the package error

Module

First, what is a module?

Module is a collection of a series of functional code.
In Python, a .py file is a module, the module file named xxx.py name is xxx, import module can refer to the function module has been written

- 模块的三种来源:
    1.python内置的模块: (python解释器的)
        比如: sys\time\os\turtle

    2.第三方的模块: (别人写的)
        比如: requests

    3.程序员自定义的模块: (自己写的)
        比如: 自己定义的demo.py文件
- 模块的四种表现形式:
    1.使用python编写的py文件。(了解)
    2.编译后的共享库DLL或者是C或者C++库。(了解)
    3.包下面带有__init__.py的一组py文件。
        - 包
            - __init__.py
            - demo.py
            - demo2.py
    4.python解释器下的py文件。
        - python解释器下的文件夹
           - 一个个的py文件

Second, why should use the module?

  • Module can help us better manage the function codes, such as: function ...
  • May be split into a number of functional items, are stored in different files py (module) of.

    Third, how to create, write module and use the module?

  • Right-click the file to create py
    - py write python code file

  • In a document by keyword import import module
    import module name
    Note: When you import the module, the module can not add the suffix .py
  • In using the module stage, it must be noted, who is the executable file, who is import the file (module to be introduced)

  • Module on the first import, imported modules has been loaded into memory, and then repeat the import will direct reference module already in memory, and will not repeat the file by import sys, you can see the value of print sys.modules already loaded into memory module name.
  • In the beginning of the file to import module belonging global scope, function module introduced in the local scope belong.

Module what happens when you import:

  1. It will first execute the currently executing file and generates the name of the currently executing file space.
  2. When executing the code module is introduced, is introduced into the module will produce a module namespace.
  3. Introduced into the module is loaded into memory namespace.
import foo      #导入模块foo
a=foo.x         #引用模块foo中变量x的值赋值给当前名称空间中的名字a
foo.get()       #调用模块foo的get函数
foo.change()    #调用模块foo中的change函数
  • To the module from the alias as
    Import module as an alias module

Fourth, the way of introducing the module

  • import module name
    - direct import import execution file

  • package from / import module name module name / (function name, variable name, class name)
    - directly in the executable file import Import

V. circulation import questions

    - m1.py
        print('正在导入m1')
        from m2 import y
        x='m1'

    - m2.py
        print('正在导入m2') from m1 import x - run.py import m1 #执行run.py会报错 - 解决循环导入问题: 1.需要查找的名字放在导入模块的上方 2.在函数内部导入,将模块加载到局部名称空间中

Six, py file distinguish two purposes: module and script

编写好的一个python文件可以有两种用途:
    一:脚本,一个文件就是整个程序,用来被执行
    二:模块,文件中存放着一堆功能,用来被导入使用
    
print(__name__)

__name__的值:

1、在文件被直接执行的情况下,等于'__main__'
2、在文件被导入的情况下,等于模块名

作用:用来控制.py文件在不同的应用场景下执行不同的逻辑

if __name__ =='__main__' func()

Seven, the module search path

Module search order :

  1. Memory modules that have been loaded
  2. Built-in module
  3. Module included in the path sys.path

Stressed : first path sys.path is currently executing the file folder where

import sys
print(sys.path)   

import sys
print(sys.modules)  #查找内存中存在的模块

Guess you like

Origin www.cnblogs.com/shenzhendaiyun/p/12143823.html