Python module description

Source: Internet
Author: User

1. Modules (variables, functions, classes, implements a function)

Package: Used to logically organize the module, essentially a directory (must have __init__.py)

2. How to Import

Import Module_alex

From Module_alex Import *

From Modele_alex import logger, running

From Modele_alex import as Logger_alex

3.import Nature (Path search and search path)

The essence of the import module is to interpret the Python file again

(Import test test = ' test.py All code ')

From test Import name = Test.name All code

Import Module_name is looking for a copy of the module in Sys.path

The essence of importing packages is to execute __init__.py

4. Import optimization from module_test Import test

5. Module classification

Standard library

Open source Module

Custom Modules

Before the import module, you need to add a path within the module that is not in the same directory

Import Os,sys

Print (Os.path.abspath (__file__)) #打印当前文件路径

Os.path.dirname (Os.path.abspath (__file__)) #返回上一级路径

Os.path.dirname (Os.path.dirname (Os.path.abspath (__file__))) #返回上上层路径

Sys.path.append (Os.path.dirname (Os.path.dirname (Os.path.abspath (__file__))) #路径的临时添加

If it is the same directory can be added directly

Python module description

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.