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

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

從包含字節(jié)數(shù)據(jù)的字符串中提取字節(jié)

從包含字節(jié)數(shù)據(jù)的字符串中提取字節(jié)

慕哥6287543 2022-05-24 13:10:53
我是 python 3 的新手,并試圖從包含消息中字符串和字節(jié)的字節(jié)數(shù)組中提取消息。我無法從解碼的字節(jié)數(shù)組中提取字節(jié)消息。首先,我解碼字節(jié)數(shù)組。然后我對(duì)解碼后的數(shù)組進(jìn)行拆分。我在拆分?jǐn)?shù)組時(shí)得到字符串值。我嘗試使用bytes(v) for v in rest.split()函數(shù)嘗試獲取字節(jié)數(shù)組,然后對(duì)其進(jìn)行解碼,但無法。# The message chunk:chunk = b"1568077849\n522\nb'l5:d4:auth53:\xc3\x99\xc3\xac\x1fH\xc2\xa3ei6eli1eee'\n"# I split the chunk into sub categories for further processing:_, size, rest = (chunk.decode("utf-8")).split('\n', 2)# _ contains "1568077849"# size contains "522" # rest contains "b'l5:d4:auth53:\xc3\x99\xc3\xac\x1fH\xc2\xa3ei6eli1eee'"我應(yīng)該能夠解碼其余變量(rest.decode(“utf-8”)),但由于它被存儲(chǔ)為字符串,我很難弄清楚如何將其轉(zhuǎn)換為字節(jié)和然后解碼值。預(yù)期結(jié)果:l5:d4:auth53:ùìH£ei6eli1eee
查看完整描述

2 回答

?
嚕嚕噠

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

這將打印您的最終結(jié)果:


chunk = b"1568077849\n522\nb'l5:d4:auth53:\xc3\x99\xc3\xac\x1fH\xc2\xa3ei6eli1eee'\n"


l1 = chunk.decode('utf-8').split()[2:]  # Initial decode

#  slice out the embedded byte string "b'  '" characters

l1_string = ''.join([x[:-2] if x[0] != 'b' else x[2:] for x in l1])

l1_bytes = l1_string.encode('utf-8')

l1_final = l1_bytes.decode('utf-8')


print('Results')

print(f'l1_string is {l1_string}')

print(f'l1_bytes is {l1_bytes}')

print(f'l1_final is {l1_final}')

Results

l1_string is l5:d4:auth53:ùìH£ei6eli1ee

l1_bytes is b'l5:d4:auth53:\xc3\x99\xc3\xacH\xc2\xa3ei6eli1ee'

l1_final is l5:d4:auth53:ùìH£ei6eli1ee


查看完整回答
反對(duì) 回復(fù) 2022-05-24
?
慕絲7291255

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

我能夠通過這種方式獲得預(yù)期的輸出:


 _, size, rest = (chunk.decode("utf-8")).split('\n', 2)

 rest = bytes(rest.replace("b'", "").replace("'", ""), "utf-8").decode("unicode_escape")



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

添加回答

舉報(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)