Getting the python module

Python module (Module1), Python is a file, ending .py, containing Python Python object definitions and statements. Module allows you to logically organize your Python code. The relevant code is assigned to a module can make your code easier to use, more understandable.
Modules can be defined functions, variables, and classes, where the module can also contain executable code.
Here is knowledge about python modules:
first understand the common python built-in module:

Os
os.path
sys
time
datetime
hashlib
base64
random
math

※ normal folder in python may act as a package, but the package is not necessarily a normal folder
to learn more about python module:
A built-in modules to know what is?

一个py或者一些py文件的总称,这些文件一般都是为了某一特定的功能而写的代码

II. Classification Module
Classification module according to the author or organization (homed)

1>内置模块:python官方提供的

Features: already installed on the system, bulitins default is introduced
as: Import random: random number all operations related to this module are placed in
Math: associated with mathematics

2>第三方模块:非官方的,有第三方提供的

Features: must be installed in order to use

3>自定义的模块: 自己写的py文件是可以被别的py文件所用的

III. Import module

①Import module_name\package
②Import package.module
③from package import module
④Import random as r(将random 使用别名 r ) 

(Python as keyword of variables, modules, methods, classes command weight)

IV. Common system module

1> Random module:

Random():返回一个[0,1)的随机数,伪随机数
Randint():返回[m,n]之间的随机整数
Choice():从一个不是空的序列(容器)中随机选择一个元素
Randrange():随机生成一个[0,x)之间的整数
Uniform:生成一个符合正态分布的数据

2> Math module: the presence of older programming language, this module is generally used to operate the mathematical operation

Ceil():四舍五入,向上取整(只要数值存在小数位,则向上取整)
Floor():只要存在小数位,向下取整
e:自然常数(e是属性)
Pi:圆周率
fabs():取绝对值
fmod(x,y):求(x%y)的模(求余数)
Log():求对数
Pow(x,y):幂次方
Sqrt():求根(开平方根)

3> Os modules: Os Operating System: operating system for operating the main file system

Import os
chdir:(类似于cd),修改当前工作空间路径
curdir:该属性表示当前目录(显示的是相对路径)   current当前
chmod :修改权限
cpu_count() : 获取当前系统的cpu核数
getcwd :表示当前路径(绝对路径)
listdir:遍历得到当前工作空间下的所有文件及文件夹(以列表的形式返回)
mkdir :创建文件夹(必须有权限)
makedirs:创建级联式的文件夹,即创建多层的
remove (文件):移除文件
removedirs:删除文件夹,注意可以多级删除,但是当文件夹里有文件时,应该不能删
rename (“文件名1”,”文件名2”):修改文件名(重命名)
renames:批量重命名
rmdir:删除文件夹,只能一级一级删,从里向外删除
scandir:遍历得到当前工作空间下的所有文件及文件夹,返回一个迭代器对象
sep:(生成\\,第一个斜杠是转义),返回系统对应的文件分隔符
system(一个命令):该方法可以执行该系统对应的所有终端的所有命令

4.os.path Module: os is a sub-module is mainly used to operate the file, determines whether the file exists, the file or folder is determined

abspath:显示相对路径的绝对路径
basename:一般而言,显示路径对应的文件名称
exists:判断文件或文件夹是否存在
getsize:获取文件大小
isdir:判断是否是目录
isfile:判断是否是文件
join:拼接路径
ismount:是不是文件挂载点
realpath:真实路径
soilt:分隔文件路径

5.sys module

※ argv(是一个参数):返回脚本名称和执行脚本时传递的参数(以列表的方式)  (可以直接拿到脚本的所有参数)
Exit():退出系统(默认穿参数为0,表示正常退出)
Getdefaultencoding():获取系统的默认编码(不一定是utf-8),如果返回值为		none,则按系统的编码走
getfilesystemencoding:获取系统文件的编码
getrecursionlimit():获取递归的限制(可以使用set…方法去修改)
getrefcount:获取变量的引用计数(python的垃圾回收机制)
path:获取所有系统变量路径
platform:获取系统平台
setrecursionlimit:设置系统对于递归的层数限制(不建议使用这个方法)
stderr:标准错误输出
stdin:标准输入
stdout:标准输出
thread_info:线程信息
version :解释器版本
version_info:解释器内核版本信息

· Python garbage collection: reference counting based, to mark and clear generational collection supplemented
· python garbage processing memory (heap memory is no longer in use):

垃圾回收机制不再由程序员管理,而是由一个系统已经制定好的线程来管理和维护内存

· Recovering heap memory is a prerequisite stack has no references to memory blocks (point) which
6. encryption module hashlib: programming, encrypted checksum
to whether reduction (reversible) algorithm can be divided into:

可逆算法:
		加密和解密是否使用同一个密钥分为:
				对称加密:相同 --使用同一个密码
				非对称加密:不同  --一对公私钥
不可逆算法:
		hash算法:
		特点:算法具有唯一性
				具有不可逆性
					有:md5,shale256

· Md5 can be anything that can be encrypted, can be used to check (use uniqueness)
· hash algorithm can encrypt anything for the 32-bit hexadecimal string
Note: md5 algorithm security issues
· MD5 although irreversible, but unique, so insecure, rainbow tables collision, and the collision probability is very high. So there are a salt value confusion .
(Rainbow table: is a cryptographic hash function for the inverse table of precalculated), salts of confusion when not in use to be verified

(Where encrypted at higher: + salt value iteration)
The first method:

Import hashlib
md5 = hashlib.MD5("要加密的数据.encode("utf-8")")
md5.update(“xxx.Encode("utf-8")”)#盐值混淆
md5.hexdigest()

The second method:

Import hashlib 				
md5 = hashlib.md5() 		
md5.update("要加密的数据".encode("utf-8")) 							
md5.update(“xxx.Encode("utf-8")”)#盐值混淆 
md5.hexdigest()

Principle salt of confusion is the xxx will be added to the end of the data to be encrypted, then encrypted, even if the break out is not the real password
7.hmac module:
new new method:
Here Insert Picture Description

	(参数1:要加密的数据,参数2:要添加的盐值,参数3:加密方法)

· Salt value to be added as a key, data to be encrypted symmetric encryption, data do it again and then encrypted hash value confusion salts, higher security

8.time module: python designed to provide time and date of the operation module

sleep:让当先线程展厅,注意单位是秒	
time:返回的是当前的时间戳(1970年1月1日0:0:0到你当前调用这个方法的秒数)
ctime:获取当前时间(可以传参数,单位是毫秒,可以通过秒来确定时间)
localtime:获取一个时间对象
strftime:将一个时间对象格式化为特定字符串
strptime:将一个特定字符串解析为时间对象

9.datetime modules:

datatime.datatime.now  获取当前系统时间

10.calendar Module: Calendar Module

Published 17 original articles · won praise 2 · Views 367

Guess you like

Origin blog.csdn.net/qq_44487069/article/details/104581279