Python Method for importing the module by path, python import module

Source: Internet
Author: User

Python Method for importing the module by path, python import module

The example in this article describes how to import the python module by path and share it with you for your reference. The specific method is as follows:

The general practice is as follows:

Import sys. path. append ('C:/full/path') from foo import util, bar

But directly through the path

Import imp util = imp. load_source ('util', 'c:/full/path/foo/util. py ')

Util. method is used. At this time, no method is defined.
Method = util. method

I hope this article will help you with Python programming.


The relative path and absolute path of python

From. import ......
From (extension package) import * (* indicates all functions in the extension package, which can also be listed in a single column, for example, from sys import exit)
And directly import xxxx

How to introduce python modules?

Before import, you can
Import sys
Sys. path. append ('your module Directory ') can import the module in this directory.

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.