Dive into Python: Import of modules and configuration of search file paths

Source: Internet
Author: User

1. Import the module in Python: Import sys; the equivalent of importing packages, classes in Java.

For example, we import the SYS module, using: Import sys;

2. When calling a function in Python, the module you are calling is searched from the default configured library folder (Sys.path). The directory configuration for this library file is as follows:

The Sys.path is used to configure the Python module search path. It is a list that prints the contents of the default Sys.path:

Python 3.3.5 (v3.3.5:62cf4e77f785, Mar 9, 10:37:12) [MSC v.1600 + bit (Intel)] on Win32
Type "Copyright", "credits" or "license ()" For more information.
>>> Import sys;
>>> print (Sys.path);
[', ' d:\\seleniumtestcase', ' c:\\python33\\lib\\idlelib ', ' c:\\python33\\lib\\site-packages\\ Setuptools-5.5-py3.3.egg ', ' C:\\python33\\lib\\site-packages\\pip-1.5.6-py3.3.egg ', ' C:\\Windows\\system32\\ Python33.zip ', ' c:\\python33\\dlls ', ' c:\\python33\\lib ', ' c:\\python33 ', ' c:\\python33\\lib\\site-packages ']
>>>

where ' D:\\seleniumtestcase ' is their own use of sys.path.apend (' d:\\seleniumtestcase '); Command added.

By adding a custom directory, you can import the module later, Python will go to you to add the source code to find the module.

Dive into Python: Import of modules and configuration of search file 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.