如何理解xml,configpraser和hashlib模塊-創(chuàng)新互聯(lián)

今天就跟大家聊聊有關(guān)如何理解xml,configpraser和hashlib模塊,可能很多人都不太了解,為了讓大家更加了解,小編給大家總結(jié)了以下內(nèi)容,希望大家根據(jù)這篇文章可以有所收獲。

創(chuàng)新互聯(lián)于2013年開始,先為信豐等服務(wù)建站,信豐等地企業(yè),進(jìn)行企業(yè)商務(wù)咨詢服務(wù)。為信豐企業(yè)網(wǎng)站制作PC+手機+微官網(wǎng)三網(wǎng)同步一站式服務(wù)解決您的所有建站問題。

寫一個XML文件

importxml.etree.ElementTreeasET
namelist=ET.ElementTree("namelist")

將namelist生成一個根節(jié)點
name=ET.SubElement(namelist,"name",attrib={"strinf":"yes","name":"alex"})

賦予namelist屬性
age=ET.SubElement(name,"age")

在根下面建立子節(jié)點
age.txt=27

賦值
role=ET.SubElement(name,"role")

根下建立子節(jié)點
role.txt="teacher"et=ET.ElementTree(namelist)

生成文件對象
et.write("test.xml",encoding="utf-8",xml_declaration=True)

寫進(jìn)一個xml文件

configparser模塊:可以生成和修改配置文件

importconfigparser
config=configparser.ConfigParser()#生成對象
config["DEFAULT"]={'Interval':'45',
                 'Compression':'yes',
                 'CompressionLevel':'9'}

賦予屬性,生成字典
config['bitbucket.org']={}可以單獨生成
config['bitbucket.org']['User']='alex'#賦值config['topsecret.server.com']={}
topsecret=config['topsecret.server.com']
topsecret['Host Port']='50022'topsecret['ForwardXll']='no'topsecret['enabled']='YES'config['DEFAULT']['ForwardXll']='yes'f=open("config.ini",'w')
config.write(f)
f.close()

在生成的文件中增刪改

importconfigparser
config=configparser.ConfigParser()
config.read("config1.ini")
print(config.sections())#找到文件的sections
config_name=config.sections()[1]

#找到對應(yīng)的值
print(config[config_name]["host port"])

sec=config.remove_option(config_name,'forwardxll')
刪除forwardx11這一行

config.set(config_name,'host port','3000')

將端口號改為3000
config.write(open("config2.ini","w"))

hashlib模塊:用來驗證文件內(nèi)容一致性的

importhashlib
m= hashlib.md5()
m.update(b"alex")
print(m.hexdigest())
m.update(b"li")
print(m.hexdigest())

讀一行的md5沒有比讀整篇的md5省內(nèi)存

m2=hashlib.md5()
m2.update(b"alexli")
print(m2.hexdigest())

m2=hashlib.sha256()
m2.update(b"alexli")
print(m2.hexdigest())

sha256的比md5的安全

加鹽算法,更安全

importhmac
hamc_name=hmac.new(b"salt",b"hello")
print(hamc_name.hexdigest())

看完上述內(nèi)容,你們對如何理解xml,configpraser和hashlib模塊有進(jìn)一步的了解嗎?如果還想了解更多知識或者相關(guān)內(nèi)容,請關(guān)注創(chuàng)新互聯(lián)網(wǎng)站制作公司行業(yè)資訊頻道,感謝大家的支持。

創(chuàng)新互聯(lián)www.cdcxhl.cn,專業(yè)提供香港、美國云服務(wù)器,動態(tài)BGP最優(yōu)骨干路由自動選擇,持續(xù)穩(wěn)定高效的網(wǎng)絡(luò)助力業(yè)務(wù)部署。公司持有工信部辦法的idc、isp許可證, 機房獨有T級流量清洗系統(tǒng)配攻擊溯源,準(zhǔn)確進(jìn)行流量調(diào)度,確保服務(wù)器高可用性。佳節(jié)活動現(xiàn)已開啟,新人活動云服務(wù)器買多久送多久。

網(wǎng)頁題目:如何理解xml,configpraser和hashlib模塊-創(chuàng)新互聯(lián)
網(wǎng)頁路徑:http://www.muchs.cn/article34/hgsse.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供面包屑導(dǎo)航、定制網(wǎng)站、移動網(wǎng)站建設(shè)、App開發(fā)、響應(yīng)式網(wǎng)站、網(wǎng)站收錄

廣告

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

成都網(wǎng)站建設(shè)公司