Python Lesson 37-Module

  1. Module (m)

Concept: In python, the file ending with .py is called a module, which can define classes, functions, attributes, etc. in the module

classification:

1). Standard library modules: modules available in the python environment after installation, these modules are the most commonly used modules;

For example: random, os, os.path, math,...

2). Third-party modules: valuable code written by others (for the world), if we need to use it,

Just need to install via pip

3). Custom module: In the process of project development, the programmers in the team define themselves, which can be used by themselves or others

Import the module:

1). Precise import:

For example:

import time

from random import randint

2). Fuzzy import:

For example:

from math import *

from os import *

Alias the imported module or its functions and attributes:

Use the as keyword to achieve

【note】:

Once an alias is created, the previous name cannot be used

Custom module:

You need to import the custom module to the current module, and then you can use the content at will

Code if name == main: The function of this code is to define the code that does not want to be loaded

" The concept of "package": package

To create a python package is to create a python package,

The role of the package: Incorporate multiple related modules to facilitate future maintenance and management

For the init.py and pycache directories, we don’t need to pay attention to it, but don’t delete it

Third-party modules:

Open cmd --> enter pip -V (this operation checks to see if the installation is complete pip)

The main operations involved are as follows:

1). View all currently installed third-party modules: pip list

2). View the detailed information of a third-party module: pip show module name

3). Install a third-party module: pip install module name for example: pip install redis

4). Delete a third-party module: pip uninstall module name For example: pip uninstall redis

# Demonstrate the import of standard library modules
import random
from random import shuffle
from math import pi,e
from time import*from random import randint as r
import os as f
# import func
# from func import my_sum

print(random.randint(1,3))

lt=[1,2,3,4,5,6]shuffle(lt)print(lt)print(pi,e)print('I slept...')sleep(2)print('I woke up...')print(r(5,10))'''
If you alias a module or function, the original name cannot be used;
So the following code will report an error
'''
print(randint(3,7))print(f.getcwd())print(func.my_sum(10,20))print(func.my_max(10,20))print(my_sum(100,200))

Recommended Posts

Python Lesson 37-Module
Python3 module
Python Lesson 32-Stack
Python Lesson 32-Queue
Python3 built-in module usage
Prettytable module of python
matplotlib of python drawing module
Python Faker data forgery module
​Full analysis of Python module knowledge
How to view the python module
Python requests module session code example
Python requests module cookie instance analysis
Python learning os module and usage
Python multithreading
Python FAQ
Python3 dictionary
python Douban replaces pip to install python module
python (you-get)
Python string
Python basics
Python descriptor
Python basics 2
Python novices learn standard library module naming
Python exec
Python notes
Python3 tuple
CentOS + Python3.6+
Python advanced (1)
Python decorator
Python IO
Python toolchain
Python multitasking-coroutine
Python overview
python introduction
Python analytic
Summary of common operations of Python time module
Python basics
How does Python handle the json module
Python basics 3
Python multitasking-threads
How to learn the Python time module
Python functions
python sys.stdout
python operator
Python entry-3
Python string
python queue Queue
Python basics 4
Python basics 5
Detailed explanation of python standard library OS module
Python uses the email module to send mail
Detailed explanation of the usage of Python decimal module
How to install the downloaded module in python