内射老阿姨1区2区3区4区_久久精品人人做人人爽电影蜜月_久久国产精品亚洲77777_99精品又大又爽又粗少妇毛片

shelve,xml,configparser,hashlib-創(chuàng)新互聯(lián)

#shelve模塊

在獲嘉等地區(qū),都構(gòu)建了全面的區(qū)域性戰(zhàn)略布局,加強(qiáng)發(fā)展的系統(tǒng)性、市場前瞻性、產(chǎn)品創(chuàng)新能力,以專注、極致的服務(wù)理念,為客戶提供成都網(wǎng)站建設(shè)、成都做網(wǎng)站 網(wǎng)站設(shè)計(jì)制作專業(yè)公司,公司網(wǎng)站建設(shè),企業(yè)網(wǎng)站建設(shè),成都品牌網(wǎng)站建設(shè),全網(wǎng)整合營銷推廣,成都外貿(mào)網(wǎng)站建設(shè)公司,獲嘉網(wǎng)站建設(shè)費(fèi)用合理。

importshelve
d=shelve.open('shelve_test')

t = Tes(123)
t2 = Tes(123334)

name = ["alex", "rain", "test"]
d["test"] = name  # 持久化列表
d["t1"] = t  # 持久化類
d["t2"] = t2

d.close()
#寫
importshelve,datetime
d = shelve.open('shelve_test')
info = {'age':22,'job':'it'}
name = ['alex','rain','test']
d['name']=name
d['info']=info
d['date']=datetime.datetime.now()
d.close()

#讀
importshelve
d = shelve.open('shelve_test')
print(d.get('name'))
print(d.get('info'))
print(d.get('date'))

#xml模塊

xmltes.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>

importxml.etree.ElementTree asET
tree = ET.parse("xmltes.xml")
root=tree.getroot()
#print(root) #文檔內(nèi)存地址
#print(root.tag) #根的名 標(biāo)簽名

#遍歷 xml文檔
forchild inroot:
    print(child.tag,child.attrib)
    fori inchild:
        print(i.tag,i.text,i.attrib #attrib屬性 text內(nèi)容
        

#只遍歷year節(jié)點(diǎn)
fornode inroot.iter('year'):
    print(node.tag,node.text)

#修改xml文檔
fornode inroot.iter('year'):
    new_year = int(node.text) + 1
    node.text=str(new_year)
    node.set("updated","yes") #修改屬性

tree.write("xmltes.xml") #寫回原文件

#刪除node
forcountry inroot.findall('country'):
    rank=int(country.find('rank').text)
    ifrank > 50:
        root.remove(country)
tree.write('output.xml')

#創(chuàng)建xml
new_xml=ET.Element("personinfolist")
personinfo=ET.SubElement(new_xml,'personinfo',attrib={"enrolled":"yes"})
name=ET.SubElement(personinfo,"name")
name.text="alex"
age=ET.SubElement(personinfo,'age',attrib={"checked":"no"})
sex=ET.SubElement(personinfo,"sex")
age.text="88"
personinfo2=ET.SubElement(new_xml,'personinfo',attrib={"enrolled":"no"})
name=ET.SubElement(personinfo2,"name")
name.text="haha"
age=ET.SubElement(personinfo2,"age")
age.text='19'

et=ET.ElementTree(new_xml) #生成文檔對象
et.write("tes.xml",encoding="utf-8",xml_declaration=True)
ET.dump(new_xml)#打印生成的格式

Configparser模塊

#用于生成和修改常見配置文檔
importconfigparser
#生成配置文件
config=configparser.ConfigParser()
config["DEFAULT"]={'ServerAliveInterval': '45',
                      'Compression': 'yes',
                     'CompressionLevel': '9'}

config['bitbucket.org'] = {}
config['bitbucket.org']['User'] = 'hg'
config['topsecret.server.com'] = {}
topsecret = config['topsecret.server.com']
topsecret['Host Port'] = '50022'# mutates the parser
topsecret['ForwardX11'] = 'no'# same here
config['DEFAULT']['ForwardX11'] = 'yes'
with
open('example','w') asconfigfile:
    config.write(configfile)
#讀配置文件
conf=configparser.ConfigParser()
conf.read("example")
print(conf.defaults())
print(conf['bitbucket.org']['user'])    #section部分

#刪除section

conf.read("example")

sec = conf.remove_section('bitbucket.org') #section部分 刪除bitbucket.org部分
conf.write(open('example.cfg','w')) #寫入 可修改原文件

#判斷section部分

conf.read("example")

print(conf.has_section("topsecret.server.com")) #存在則為true

#添加section

conf.read("example")

sec2=conf.add_section("HOST")

conf.write(open('example.cfg','w'))


#修改section下的key value
conf.read("example.cfg")

conf.set('HOST','hostname_ip','192.168.0.1')  #conf.set(section,'key','value')
conf.write(open('example.cfg','w'))

#hashlib模塊

importhashlib
#用于加密相關(guān)的操作
m = hashlib.md5()
m.update(b'hello') #update疊加 獲取hello的md5值
print(m.hexdigest()) #十六進(jìn)制 輸出并打印hello的md5值
m.update(b"It's me")
print(m.hexdigest())
m.update(b"It's been a long time since last time we ...")
print(m.hexdigest())

print('----------------------------------------')

m2=hashlib.md5()
m2.update(b"helloIt's me")  #拼起來
print(m2.hexdigest())


s2=hashlib.sha256()
s2.update(b"helloIt's me")
print(s2.hexdigest())

importhmac
#對我們創(chuàng)建 key 和 內(nèi)容 再進(jìn)行處理然后再加密 用于消息加密
h = hmac.new('天王蓋地虎'.encode(encoding="utf-8"),'寶塔鎮(zhèn)河妖'.encode(encoding='utf-8'))
print(h.digest()) #十進(jìn)制
print(h.hexdigest())

另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)scvps.cn,海內(nèi)外云服務(wù)器15元起步,三天無理由+7*72小時售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國服務(wù)器、虛擬主機(jī)、免備案服務(wù)器”等云主機(jī)租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡單易用、服務(wù)可用性高、性價(jià)比高”等特點(diǎn)與優(yōu)勢,專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應(yīng)用場景需求。

網(wǎng)頁題目:shelve,xml,configparser,hashlib-創(chuàng)新互聯(lián)
轉(zhuǎn)載注明:http://www.rwnh.cn/article28/jdojp.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站改版、品牌網(wǎng)站設(shè)計(jì)、動態(tài)網(wǎng)站、企業(yè)網(wǎng)站制作網(wǎng)頁設(shè)計(jì)公司、建站公司

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

網(wǎng)站托管運(yùn)營
盐亭县| 越西县| 乌兰浩特市| 库伦旗| 广灵县| 工布江达县| 隆化县| 贵阳市| 三河市| 满城县| 伊川县| 宁化县| 炉霍县| 孟村| 漳平市| 当阳市| 汤阴县| 韶山市| 孝昌县| 灵宝市| 永清县| 英吉沙县| 焦作市| 辽宁省| 临桂县| 长岛县| 灵璧县| 荥经县| 施秉县| 儋州市| 都兰县| 桐梓县| 廊坊市| 邳州市| 崇明县| 广汉市| 宝丰县| 开鲁县| 凯里市| 五寨县| 吕梁市|