5. Move the end Automated Test - Tips and import from ... import of difference

A .import

 
  1. 1

    When import imported module name defined need.

    For example, we first create a md.py file, which has a function

    Python module (b) import and from ... import of difference
  2. 2

    Then reference this function in 1.py file.

    Note that we need to use md. Way call. Module name if not defined, will be given

    Python module (b) import and from ... import of difference
  3. 3

    For example, this way, we get rid of the qualified name of the module, on the error

    Python module (b) import and from ... import of difference
    Python module (b) import and from ... import of difference
    END

二.from...import

 
  1.  

    And no need to add is defined from import module name. Look at the following example, the right to print the results.

    Python module (b) import and from ... import of difference
    Python module (b) import and from ... import of difference
  2.  

    from md import * mean, imported all the modules.

    We can import only the specified portion of the current namespace.

    As shown below, we have modified the md module, which has three functions

    Python module (b) import and from ... import of difference
  3.  

    We modified the 1.py file and import function of the two of them. Seen on the results, the last sentence of the error. Because we do not have to import all the files, import only the two functions only.

    Python module (b) import and from ... import of difference
    Python module (b) import and from ... import of difference
  4.  

    We now add a file md2.py, which wrote a function of alsp

    Python module (b) import and from ... import of difference
  5.  

    We 1.py while quoted md and md2 module, use from import way

    Python module (b) import and from ... import of difference
  6. 6

    Results are as follows, the second sentence of a first import cover, the second sentence is executed md2 function module alsp

    Python module (b) import and from ... import of difference

Guess you like

Origin www.cnblogs.com/yinlili/p/11309998.html