#导入模块干了哪些事:
#1 Execution Source files
#2 the global namespace as a source file
#3 get a module name at the current location, point to the namespace created by 2
# Import Spam
# money=100000000000
# def READ1 ():
# print (' from Test ')
# # print (Spam.money)
# # print (SPAM.READ1)
# # SPAM.READ1 ()
#
# # SPAM.READ2 ()
# Spam.change ()
# Print (Money)
# Spam.read1 ()
#
# Import spam as S1
# Print (S1.money)
# sql_type=input (' Sql_type: ')
# if Sql_type = = ' MySQL ':
# import MySQL as SQL
#
# elif Sql_type = = ' Oracle ':
# import Oracle as SQL
#
# Sql.sqlparse ()
Import Sys
Print (SYS)
Import spam
Print (spam)
#优点: Use the name in the source file without prefix, easy to use
#缺点: Easy to confuse with names in the current file's namespace
# From spam import Money,read1,read2,change
# money=0
# Print (Money)
# Print (READ1)
#
# Read1 ()
# def read1 ():p rint (' OK ')
# read2 ()
#
# money=10
# change ()
# Print (Money)
# From spam import money as M
#
# Print (m)
From spam import *
# Print (_money)
# Read1 ()
# Print (READ2)
Print (Money)
Print (x)
Print (READ1)
#模块只在第一次导入时才会执行, the subsequent import is a direct reference to the memory already existing results
Import Sys
Print (' spam ' in sys.modules) #存放的是已经加载到内的模块
Import spam
Print (' spam ' in sys.modules)
# Import Spam
# Import Spam
# Import Spam
# Import Spam
# Import Spam
The 5th chapter uses the Python module