Python modules and Paths

Source: Internet
Author: User

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

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.