Problems with Python module import

Source: Internet
Author: User

When you import a function from a module, you can usually use the

Import   Somemodule

Or

 from  Somemodule  Import  somefunction

Or

 from  Import   Somefunction  , Anotherfunction  , yetanotherfunction

Or

 from  Somemodule  Import  *

The last version should be used only if you are sure you want to import all features from a given module, but what about the same function for all two modules?

Just use the first way to import, and then use the function as follows:

Module1.open (   ) Module2.open (    )

But there is another option: You can add an as clause at the end of the statement, giving the desired alias after the clause, such as providing an alias for the entire module:

Import    Math   as   foobarfoobar.sqrt (4)

or provide an alias for the function:

 from   Math   Import   sqrt   as   Foobarfoobar (4)

Problems with Python module import

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.