Both methods Python import modules: import xxx and from ... import xxx

 

Import module import mode

Import tool.getsum.add
 # import modules, priority will begin looking for start-up files from the current directory 
# If found, use 
# If not, the module will be stored in the system directory to 

tool.getsum.add.add2num ( 2, 5 )

 

      Example:

C:\Users\Tom> python
Python 3.6.5 (v3.6.5:f59c0932b4, Mar 28 2018, 17:00:18) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import time
>>> print("Current Time: %F" % time.time())
Current Time: 1575719563.011607
>>> print("Current Time: " + time.strftime("%Y-%m-%d %X"))
Current Time: 2019-12-07 19:57:07

 

from…import

  • Import module

from tool import add
add.add2num(3,9)

# import tool.add
# tool.add.add2num(3, 9)

 

  • Import module identifier

    • I. specified identifier to import
# From ... import .... 
# what what what what identifiers from module import


from getsum.add import add2num

add2num ( 3,7 )

import identifier specifies what to what. Not specified identifiers available
    • Case 2, all introduced in the identifier module, by everything *
from getsum.add import *

add2num(3,7)
print(name)
print(age)

This implementation, to pay attention to the name of the conflict

 

 

Guess you like

Origin www.cnblogs.com/morgan363/p/12003118.html