Python Learning Day 16th: process-oriented programming, modules

Source: Internet
Author: User

Process-oriented programming

Process-oriented core is the process, refers to the steps to solve the problem, that is, what to do first, as if designing a pipeline.

Advantages: Complex problems are streamlined and simplified

Disadvantage: Poor scalability, modify any stage of the pipeline, will be reaching

Applications: Scenarios with low scalability requirements, typical cases such as frameworks, Linux kernels, git

Module

1. What is a module?

A module is a collection of functions.

Common module Forms: custom modules, third-party modules, built-in modules

Four types of categories:

①.. py files written using Python

②. A folder containing __init__.py files (called packages) that organizes a series of modules together

③. C or C + + extensions that have been compiled as shared libraries or DLLs

④. Built-in modules written and linked to the Python interpreter using C

2. Why use the module:

Use of third-party modules and built-in modules can greatly improve development efficiency

Use of custom modules to make our programs clearer, easier to manage, and reusable for functionality

3. How to use the module: Import .... from ... import .....

There are three things to do when importing a module for the first time:

①. To create a module namespace, whichever module (the module is imported)

②. Execute the module corresponding to the file code, the execution of the name generated in the process is thrown into the module namespace

③. Get a module name in the current execution file

Note: Duplicate import does not execute file

The imported module has a separate namespace

Alias: Import Time AAS TM

More than one line: import Time,os

Comparison of From...import and import

The only difference is: Use from...import ... is to import the name in the spam directly into the current namespace, so in the current namespace, the name can be used directly, without prefix

From...import *

Note: In most cases our Python program should not use this type of import, because * you do not know what name you import, it is likely to overwrite your previously defined name. And the readability is extremely poor, there is no problem when importing in an interactive environment.

4. Search Path:

Order of search paths:

①. In-Memory imported

②. Built-in Modules

③. Environment variables

5. Two uses:

①. Script: A file is the entire program, used to be executed

②. Module: A file contains a bunch of features that are used for import

  

When a file is executed as a script: __name__ equals ' __main__ '

When a file is imported as a module: __name__ equals module name

6. Software Development Specification

Python Learning Day 16th: process-oriented programming, 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.