Import Sys
#import module (. py)
Import Functools #名词空间 Functools
Print (Functools)
Print ("-------------os----------------------")
Import Os.path #dir--noun space os;;os&path is two py files
Print (OS)
From inspect import Signature
Print (signature.__module__) #return from which module to import
Print ("-----------alias--------------------")
Import Os.path as OSP #dir--Noun space OSP
Print (OSP)
Print ('-----------from_import---------------')
From pathlib import Path #dir---Noun space path
From pathlib import * #dir-->[' Path ', ' posixpath ', ' PurePath ', ' pureposixpath ', ' Purewindowspath ']
Import Pathlib as PL #导入的名词和别名是一个对象
From Os.path import exists #加载初始化os, Os.path, exists joins the local noun space and binds
print (pl. Path,id (pl. Path))
Print (Path,id (Path))
"' Part1 Summary
Locate the module specified in the FROM clause, load and initialize it (note that it is not imported)
Import clause first checks whether the module imported by the FROM clause has a property of that name, if it is not an attempt to import a submodule of that name
No thrown importerror exception was found, this name is saved to the local noun space, and if there is an as clause, the name after using the AS clause
‘‘‘
Print ("------------costomize----------------")
"""
The module name is the file name, must conform to the requirements of the identifier, not the beginning of the alphanumeric underscore combination
Search Order Sys.path
"""
Print ("------------__name__ = = __main__-----------------------")
‘‘‘
Own module calls to perform tests, for non-master modules, test function classes within this module
The top-level code is not encapsulated, the main module is not a problem to use, but once the new master module is available, the old main module becomes the imported module.
Since the old module code is not encapsulated, it is executed in conjunction with
‘‘‘
Print ("-------------relative import-------------------------------------")
‘‘‘
The relative import module is for the package between the medical resources, that is, not as the main function of the portal
‘‘‘
Print ("----------------__all__-----------------------------------")
‘‘‘
#a. py
__all__ = [' x ', ' y ', ' _b ', ' __c ']
A = 5
_b = 6
__c = 7
x = 10
y = 20
#b. py
From b Import *
Import Sys
Print (sorted (Sys.modules.keys ()))
Print (Locals () [' X '])
Print (Locals () [' __c '])
__all__ is a list, the element is a string, each element is a variable name within the module, import, import __all__ inside the name
Access to variables in a can be accessed by __all__
‘‘‘
Print ("----------Public Module Properties---------------------")
Print (__file__) #当前文件的路径
Print (__cached__) #编译后的字节码文件路径
Print (__spec__) #显示模块的的规范
Print (sys.path) #output Search Path Order
Print (__name__) #output __main__
Print (__package__) #模块是包同__name__, otherwise. An empty string that can be set to the top-level module
Print (dir ())
Print (Sys.modules)
Python module Import