首页 > 编程语言 > 详细

Python全栈开发——hashlib和configparser模块

时间:2018-09-30 00:18:47      阅读:265      评论:0      收藏:0      [点我收藏+]

1.configparser     #与配置文件有关

技术分享图片

import configparser

#相当于创建空字典
config=configparser.ConfigParser()

config[man]={
    name:lujiacheng,
    age:15,
    sex:man,
}

config[woman]={}
tog=config[woman]
tog[name]=alex
tog[age]=18
tog[sex]=woman

config[love]={}
config[love][fourtile]=love

with open(looger,w) as f:
    config.write(f)        #写入文件
#-----------------
import configparser

config=configparser.ConfigParser()
config.read(looger)            #与配置文件建立关系
print(config.sections())         #读配置文件
   #[man, woman, love]

print(man in config)     #判断是否存在
#True

print(config[man][name])  #查
#lujiacheng

for each in config[woman]: #遍历,若文件中有[DEFOULT]配置文件,也会打印
    print(each)
# name
# age
# sex
# window

#-----------------------------增删改(最后都要有config.write(open(‘j.txt‘,‘w‘)))
import configparser
config=configparser.ConfigParser()
config.read(looger)

config.add_section(yuan)        #增加一块
config.set(yuan,price,100)   #增加键值对
config.remove_section(woman)     #删除一块
config.remove_option(man,age)           #删除一块中的一部分

config.write(open(j.txt,w))

hashlib模块
import hashlib
#obj=hashlib.md5()  #建立Md5算法,默认可破解
obj=hashlib.md5(lujiacheng.encode(utf-8))   #加盐,很难破解
obj.update(hellow.encode(utf-8))

print(obj.hexdigest())
 

 

Python全栈开发——hashlib和configparser模块

原文:https://www.cnblogs.com/lujiacheng-Python/p/9727201.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!