The difference between the import of Python and From...import

Source: Internet
Author: User

"Turn" http://blog.csdn.net/windone0109/article/details/8996184

Import the appropriate modules in Python using Import or From...import. module is actually a collection of functions and classes of files , it can achieve some of the corresponding functions, when we need to use these functions, the corresponding modules directly into our program, it can be used. This is similar to the Include header file in the C language.

ImportSYSPrint('======================python Import mode========================')Print('The command line arguments is:') forIinchSYS.ARGV:Print(i)Print('\ nthe python path', Sys.path) fromSysImportArgv,path#import a specific memberPrint('======================python from import=========================')Print('Path:', path)#because the path member has already been imported, it is not required to be written as Sys.path#If you want to use a name that is used by all SYS modules, you can fromSysImport*Print('Path:', path)

From the above we can simply see, import module imports and From...import differences, simply say:

If you want to use ARGV in your program to represent SYS.ARGV, you can use

 from Import argv

In general, you should avoid using the import statement with From...import because it makes the program easier to read and avoids conflicting names.

The difference between the import of Python and From...import

Related Article

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.