python之configparser、hash与subprocess模块

Day 09 configparser、hashlib与subprocess模块

1. configparser模块

加载某种特定格式的配置文件

[section1]
option
[section2]
optiion

#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
import configparser
config=configparser.ConfigParser()
config.read('路径')
config.sections()#获取section
config.options('sections1')#获取某一section下所有options
config.items('sections1')#获取某一section下所有options及其所有值
config.get('sections','user')#某一个具体的配置

2.hashlib模块

2.1 hash

是一类算法,为该算法接收传入的内容,经过一系列运算得到一串的hash值

hash值的特点:

  • 内容一样,hash值一样
  • 只要hash算法不变,无论内容多大,hash值长度不变
  • 不能由hash反解成内容

hash的用途:

  • 文件校验(校验hash值)
  • 密文密码传输与验证
import hashlib
m=hashlib.md5()
m.update('hello'.encode('utf-8'))
m.update('world'.encode('utf-8'))
res=m.hexdigest()
print(res)

3.subprocess

用于执行系统命令

import subprocess
obj=subprocess.Popen('dir d:\\pyt',shell=True,stdout=subprocess.PIPE,stderr=subprocess.PIPE)#out是标准正确输出的管道;err是标准错误输出的管道
err_res=obj.stdout.read()
err_read=obj.stderr.read()
print(err_read)
print(err_res.decode('gbk'))#linux编码utf-8,windows编码gbk
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值