A base module

Module basis -> how import module

python modules commonly used: numpy / pandas / matplotlib (data analysis must be proficient <Data analysis was performed using the python>)

29 pm -> module, regardless of atm

Module

python as your phone -> pip as steward Applications -> module is the application software

Module Category:

  1. Module system comes -> no need to install

  2. You need to download the module

  3. Custom modules

  4. Built-in module: python interpreter built-in module to start, time / random / os / sys ...

  5. Installation module pip: pip install jieba / pycharm installation

  6. Custom Module -> custom code

  7. Package (block)

What is a module?

Module -> code implements a specific function -> easier

import time 和 from ......import.py

import time

The program runs to import time this line, it will automatically perform the following three steps:

1, opening up memory space, memory space named time:

2, all the code is read into time.py namespace, and then run

3, by the time. The method of use of the name of the time module

time.sleep(1)

from module import name method name

from time import sleep

The program runs to import time this line, it will automatically perform the following three steps:

1, opening up memory space, memory space named time:

2, all the code is read into time.py namespace, and then run

3, the sleep () reads the import and form ... import.py, a method name can be used directly

sleep(0.01)

If you want to use multiple methods, proceed as follows:

from time import sleep, time, # write the name of the method you want to use in the import behind, separated by commas

If you want to import all methods

from time import * # import all the features

The advantages and disadvantages of both

import

Advantages: Never conflict

Cons: multiple input several characters when you call inconvenient

from ...... import......

Advantages: less input characters when calling

Disadvantages: prone to conflict

Custom Modules

Their own definition of a module to prepare for call

Use of custom modules: sub-file storing code, a function to separate the functions, diamagnetic more clearly, specific module is responsible for specific functions

Circulation import

When the cycle import method with the basic method, will complain (not into the loop, because once open only to the module memory space)

There are two solutions:

First, before importing define objects to be imported

Second, the definition of the object to be introduced in the function because the function detects only the syntax, the code is not performed

The module search path

Mainly refers to the module search path:

1, memory

2, built-in

3, custom

Memory -> Built -> Customize

Two uses python file

First, as an executable file: The current file is run the executable file

Second, as the module file: it is introduced into other executable file

__name__ is unique to each file.

When the file is run as an execution file, __ name __ equal to '__ main __';

When the document file is imported as a module, __ name __ equal to the file name

Guess you like

Origin www.cnblogs.com/allenchen168/p/11594453.html