Note the module package Python3 ||

The module concept: a .py file is called a module.

Concept of packages: the plurality of modules according to function in a different directory is organized into modules, the module file directory to store these organizations, we call package.

Advantages module package: 1- convenient to call someone else

                       2 - avoid overlapping variables / functions

                       3 - variable name scope for each module in the module only

Custom modules: Module definition file is created py

                 Py module name is the file name

                 Module identifier may comprise for external use

                       Variable (some constants, such as configuration items)

                       Function (for call other modules)

                       class

* * Note: the same name ----- try to avoid the same name

             The alias import test1 as t ------

             A number ------ separated by commas, or write separately import

Use of modules:

       1 - Call within the same package

             import module name ----- equivalent to executing again import module

             Use variables / functions: Import behind the content   Functions / Variables

             If the module name long ----- AS alias can be reduced character length; at the same time avoid introducing 2 / which has the same name as a function of a plurality of modules, covering the situation

             import function module name from / variables such as ----- from mathFunction import * <==> import mathFunction

             Difference: ① import xxxx ----- Import All

                      ② from module import function / variable content import ------ specified, if the latter increase, then add the contents of the back of the import

        2 - call different packages

              The import testP.pTest testP.pTest.func ()

        3 - __init__.py module: ① ② initialization as long as you call this package, then this package __init__.py is executed.

Using standard library: including functions and built-in types, such as len, int, open like; used without import.

                    Function modules: function comprise common programming required, they need to import introduction can be used.

                    According to the document view usage details.

       Import ① programmers do not need to use variables and functions directly ---- ---- import / open / len

       ② import time    -----  print(time.strftime("%Y_%m_%d %H%M:%S"))

       ③ standard library 1-- & built-in type built-in functions do not need to import ---- --- directly

                       2 - To use the built-in module --- import     

                       from  datetime import  date   

                                  now = date.today()

                                  print(now)

Module Search rules :

         Sys.path value is how come? ------------- automatically added to the directory where the startup script

         Automatically added to the standard library directories such as: D: \\ tools \\ python36 beginning

         PYTHONPATH environment variable contains the directory. This is an environment variable, if not set are ignored set PYTHONPATH = d: \

         lib / site-packages the following file path specified .pth

        1 - import sys  ------ sys.path 

        2 - sys.path ------ ------ first address the current directory is empty

Increase Path : 1 - import sys temporary

                        sys.path.append('g:/file')

               2 - cmd --- set PYTHONPATH=g:/file

Third-party modules : in python, third-party modules, through the complete package management tools pip.

                       If you are using a Mac and Linux, you can skip the installation pip.

                       If you are using windows, when you install python, make sure you check pip and Add python.exe to Path

                       Try running the command prompt window pip, if not receive any command, you can re-run the install program to add pip

                       * * Note: It is possible on Mac and Linux coexist Python3 and Python2, therefore pip corresponding command is pip3

              Related command - 

                     Installation (using PIP) -------- pip install selenium

                     Find the path ------- where pip pip  

                     What if the direct pip internal error, basically environment variable problem, carefully check the next! !

                     Uninstall command ----- pip uninstall selenium

                     Specified version ----- pip install SomePackage == 1.0.4

                     Update Installation ----- pip install selenium -u

Guess you like

Origin www.cnblogs.com/peipei-Study/p/11942707.html