第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

逐行讀取原始二進(jìn)制文件,將其轉(zhuǎn)換為 ascii,并以相同的方式以.txt格式存儲(chǔ)

逐行讀取原始二進(jìn)制文件,將其轉(zhuǎn)換為 ascii,并以相同的方式以.txt格式存儲(chǔ)

慕的地6264312 2022-08-16 19:00:48
我能夠逐行讀取原始二進(jìn)制數(shù)據(jù),但無(wú)法將其逐行存儲(chǔ)到.txt文件中。有人可以幫我嗎?這是我的代碼:with open("aa.dwr", "rb") as file:  data = file.readline()  datastring = str(data)  while data:    with open("out1.txt", "w") as f:      f.write(' '.join(map(str,data)))      f.write("\r\n")    print("line {}: {}".format(cnt, map(str,datastring.strip())))    data = file.readline()    cnt +=1
查看完整描述

2 回答

?
呼喚遠(yuǎn)方

TA貢獻(xiàn)1856條經(jīng)驗(yàn) 獲得超11個(gè)贊

with open("out1.txt", "w") as f:

    while data:

        f.write(' '.join(map(str,data)))

        f.write("\r\n")

        print("line {}: {}".format(cnt, map(str,datastring.strip())))

        data = file.readline()

        cnt +=1

請(qǐng)像這樣嘗試...


或者你可以試試


while data:

    with open("out1.txt", "a") as f:

        f.write(' '.join(map(str,data)))

        f.write("\r\n")

    print("line {}: {}".format(cnt, map(str,datastring.strip())))

    data = file.readline()

    cnt +=1


查看完整回答
反對(duì) 回復(fù) 2022-08-16
?
達(dá)令說(shuō)

TA貢獻(xiàn)1821條經(jīng)驗(yàn) 獲得超6個(gè)贊

如果您的原始數(shù)據(jù)是字符串編碼為二進(jìn)制文件,那么您可以讀取二進(jìn)制文件,然后將其解碼為字符串。然后逐行拆分字符串并將其寫入文件。

僅當(dāng)要將文本逐行拆分為字符串時(shí),這才適用。如果你想像@Selcuk提到的那樣逐行拆分二進(jìn)制,這意味著什么?


with open("file.b", "rb") as f:

     data = f.read()

     data = data.decode()

     lines = data.splitlines()


     with open("out.txt", "w") as f2:

         for line in lines:

             f2.write(line + "\n")


查看完整回答
反對(duì) 回復(fù) 2022-08-16
  • 2 回答
  • 0 關(guān)注
  • 130 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)