1. Built-in Modules
2. Extended For example: Django
3. Custom-Defined
File
Import Demo
def read ():
Print (' My read Func ')
Demo.read ()
Print (Demo.money)
Check to see if it has been imported from Sys.modules first.
If not imported, the search module is based on the Sys.path path
When you find it, import it.
Create namespaces for this module
Execute the file and put the name in the file in the namespace
Import Sys
Print (Sys.modules.keys ())
Print (Sys.path)
Import time as T
Print (T.time ())
Import * * * for:
Oracle
Mysql
If database = = ' Oracle ':
Import Oracle as DB
elif Database = = ' MySQL ':
Import MySQL as db
Connecting to a database Db.connect
Login Authentication
Change and delete
Close the database
Like a database, you can do this by matching and selecting the as * * * and finally using a variable name.
All module imports should be written as far as possible.
Built-in Modules
Expansion modules
Custom Modules
The module will not be imported repeatedly: Sys.moudles
Where to import the module: Sys.path
Mport Module Name
Module name. The variable name does not conflict with the variable name in this file
Import module name as renamed Module name: Improved code compatibility
Import Module 1, Module 2
From module name import variable name
Use the variable name directly to complete the operation
If there is a conflict with the same variable name in this file
From Module name Import *
Put all the variable names in the module into memory
If there is a conflict with the same variable name in this file
From Module name import * and __all__ are a pair
Without this variable, all the names will be imported.
If you have all only import names from the all list
__name__
There is a variable __name__ in the module,
When we execute this module directly, __name__ = = ' __main__ '
When we execute other modules and refer to this module in other modules, the __name__ = = ' Module name ' in this module
Modules in Python (2)