hash

什么是hash?

         hash是一种算法,该算法接受传入的内容,经过运算得到一串hash值

为何用hash?

         hash值有三大特性:

         1.只要传入的内容一样,得到的hash值必然一样

         2.只要使用的hash算法固定,无论传入的内容多大,得到的hash值的长度是固定的

         3.不可以用hash值逆推出来的内容

         基于1.2可以用于下载文件时做一致性校验等

         基于2.3可以用于密码的加密等

如何使用hash

         import hashlib

         m = hashlib.md5()  # 相当于造工厂

         m.update(‘hello’.encode(‘utf-8’))  # 相当于送原料

         m.hexdigest()  # 相当于产出产品

 

shelve

import shelve  # 序列化,将内容以字典的形式存入文件
f=shelve.open(r'sheve.txt')
# f['stu1_info']={'name':'egon','age':18,'hobby':['piao','smoking','drinking']}
# f['stu2_info']={'name':'gangdan','age':53}
# f['school_info']={'website':'http://www.pypy.org','city':'beijing'}
print(f['stu1_info']['hobby'])
f.close()

 

xml

<?xml version="1.0"?>
<data>
    <country name="Liechtenstein">
        <rank updated="yes">2</rank>
        <year>2008</year>
        <gdppc>141100</gdppc>
        <neighbor name="Austria" direction="E"/>
        <neighbor name="Switzerland" direction="W"/>
    </country>
    <country name="Singapore">
        <rank updated="yes">5</rank>
        <year>2011</year>
        <gdppc>59900</gdppc>
        <neighbor name="Malaysia" direction="N"/>
    </country>
    <country name="Panama">
        <rank updated="yes">69</rank>
        <year>2011</year>
        <gdppc>13600</gdppc>
        <neighbor name="Costa Rica" direction="W"/>
        <neighbor name="Colombia" direction="E"/>
    </country>
</data>
xml源码

相关文章:

  • 2021-07-23
  • 2021-10-09
  • 2021-10-27
  • 2022-01-11
  • 2021-12-10
  • 2021-08-04
猜你喜欢
  • 2022-12-23
  • 2021-05-27
  • 2021-04-10
  • 2021-06-27
  • 2021-11-19
  • 2022-02-21
相关资源
相似解决方案