Python basic 5 common modules

Source: Internet
Author: User

1. Definition:

A module used to logically organize Python code (variables, functions, classes, logic: Implementing a function), essentially the. PY result of the Python file (file name: test.py corresponding module name: TEST) Package: It is used to logically organize the module, which is essentially a directory ( Must have a __init__.py file)

2. How to Import

Import module_name #导入一个模块import module_name,module2_name #导入多个模块from module_name Import * #定义导入模块下所有的方法导入 Operation not recommended) from MODULE_NAME import M1 m2 m3from module_name import logger as Logger_alex

3.import Nature (Path search and search path)

The essence of the import module is to interpret the Python file once (import Test test= ' test.py All code ' defines a variable test, which points to the area of memory) (from test import name name= ' code ') IM Port module_name----->module_name.py Path--->sys.path-----the >module_name.py
The essence of the import package is to execute the __init__.py file under the package

4. Import optimization

From module_name import test as Test_one #执行导入模块test, import once, use the test method multiple times

5. Classification of modules:

A: standard library B: Open source module C: Custom module


Python basic 5 common modules

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.