zoukankan      html  css  js  c++  java
  • Python全栈开发——hashlib和configparser模块

    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())
     
  • 相关阅读:
    opennebula 编译日志
    eclipse scons 使用指南
    eclipse 安装scons
    在Windows7上搭建Cocos2d-x 3.2alpha0开发环境
    Centos6.3 jekyll环境安装
    CNN-利用1*1进行降维和升维
    偏导数
    卷积神经网络--CNN
    struts2 模型驱动
    Struts2 数据驱动
  • 原文地址:https://www.cnblogs.com/lujiacheng-Python/p/9727201.html
Copyright © 2011-2022 走看看