1 #Remember that you cannot have the same name as the method function, or you will get an error! 2 3 #Python's modules and packages are divided into three types:4 #1. Standard library5 #2. Third-party modules6 #3. Custom Modules7 8 #the introduction of the Python Module principle:9 #join you create a module, after the import module, Python will interpret the contents of the module and re-assign to the module objectTen #so you can call the module object directly when you are using it to handle One A #you have to consider, if there is a lot of content in this module, and you only need to use part of the content, consider the efficiency problem, how to improve efficiency? - #using the FROM keyword - #From Module Name Import method name, method name the #From calcute Import * - #from WEB.WEB2 Import logger web2 as a Web sub-module - #form Web.web2.logger Import log gets the specific method under the Logger module log () - #import only for the current path to find the package + #Call Package What happened to find the data in the __init__.py module below the package
1 #the main method of executing the program here2 #From moudle Import main3 #Main.main ()4 #The above is no different, but the pycharm default is to find the absolute path of the program5 6 #the correct method is as follows:7 #print (__file__) #相对路径的绝对表现形式 e:/3-Practice Library/atm/bin/bin.py8 #I need to return the root of this directory structure relative structure9 #os.path.dirname () is equivalent to getting the parent level of the directoryTen #and then add this path to the link variable to make the call. One ImportOS A ImportSYS -Base_dir =os.path.dirname (Os.path.dirname (__file__))#e:/3-Practice Library/ATM equivalent to/atn - sys.path.append (Base_dir) the - #Here we start importing modules. - - fromMoudleImportMain +Main.main ()
Python modules and Paths