Module
# module Definition: Classify some complex functions that need to be reused and put
# into the same py file, you need to call the time to use it directly.
# import Xiaomei
# I. What to do when importing modules
# 1. First look at your own memory there is no, some words will not work, not in the pour in
# 2, create a namespace, execute code in this namespace
# 3. Create a name for Xiaomei that binds variables and Xiaomei in the namespace
# 4.import The contents of the import module and the content in the file being manipulated will not conflict
# import Sys
# Print (sys.modules)
# we can find the currently loaded module from Sys.modules, Sys.modules is a dictionary
#, internally contains the mapping of the module name to the module object, which determines whether the import module needs to be re-imported
# def Drive ():p
# xiaomei.drive () #执行模块里的函数
# Print (Xiaomei.price)
# Two. Import ... as: Rename the module, the name before the rename expires, the new name can be
# to use directly
#1. Import's name is too long an alias
# 2 When the import module has the same name as the variable in my file
#3当兼容多个模块的相同操作的时候
# import Xiaomei as XM #import的名字太长起一个别名
# xm.drive ()
# import Xiaomei as XM #当import的模块和我文件中的变量重名的时候
# def Xiaomei ():
# print (123)
# xm.drive ()
# if is MySQL database: #当兼容多个模块的相同操作的时候
# import MySQL as db
# elif is an Oracle database:
# import Oracle as DB
# Db.open
# Db.write
# three. Import multiple modules
# import Os,re,time #python支持这种语法, but it is not recommended to import multiple modules at the same time
# Rules for importing modules: Import the built-in modules first
# Re-import Extension module: Requests BeautifulSoup Django Selenium Paramikl
# Last import of custom modules
# from Xiaomei import Drive,price
# from Xiaomei import drive as d,price as P
# Drive ()
# The usage of the from import places the imported content directly in the global, but the variable and drive method used in drive is a binding
# relationship, if there is the same name, overwrite will occur
# Test Three: Imported function Read1, overwritten by the read1 defined by the current location
# #demo. py
# from My_module import read1
# def READ1 ():
# print (' ========== ')
# Read1 ()
# ‘‘‘
# Execution Result:
# from the my_module.py
# ==========
# ‘‘‘
# Use the Import module name when you want to use multiple methods in this module
# Use the From Module name import function name when using only one or two of the modules
# Not recommended for use with form import*
# import Xiaomei
# from Xiaomei Import *
# from Xiaomei import Drive,price
# Drive ()
# Print (Price)
# from Xiaomei Import *
# * Subject to _all_ restrictions, if you do not define _all_ the default is to introduce all
# if defined, what can be introduced in the list, but does not affect the use of variables not introduced, only need to
# from Module name import variable name to use the variable in the module normally
# import Xiaomei
# Print (drive)
# Print (Price)
# from Xiaomei import price
# Print (Price)
# The module will not execute the code in the module after it is imported again, if the module has been modified,
# is not recognized, you can see the effect by reloading it with the Importlib module
# import Time,importlib
# import Xiaomei
# xiaomei.drive ()
# TIME.SELLP (10)
# importlib.reload (Xiaomei) #加载修改过后的模块内容
# print (' Price: ', Xiaomei.price)
# import Xiaomei
# import RE
# import Sys
# Print (sys.modules)
# Print (Sys.path)
# executes the Python interpreter, has loaded some built-in modules in memory, when importing the module, if the module does not exist
# in the Sys.modules, only from the path given by Sys.path to find in turn
# Sys.path can completely determine if a module can be found (except for some built-in modules that have already been loaded in memory)
# import Xiaomei
# When a py file is imported as a module, a PYC file is automatically generated,
# PYC file is a file that is compiled after this code, saving the time to compile each time after importing the code
# import Xiaomei
# Print (dir (Xiaomei))
# import Builtins
# Print (dir (builtins))
python-Modules and Packages