The 5th chapter uses the Python module

Source: Internet
Author: User

#导入模块干了哪些事:

#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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.