簡體   English   中英

字節和字符串 python

[英]bytes and strings python

encoding = ('utf-8')
data = b"C:\Users\victim\Desktop\test1.exe"
print (data.decode(encoding))

當我運行它時,我得到以下 C:\Users[]ictim\Desktop est1.exe 我需要得到的是 C:\Users\victim\Desktop\test1.exe

您需要轉義\字符,否則它會拾取旁邊的字符並將其作為\t 嘗試:

>>> encoding = ('utf-8')
>>> data = b"C:\\Users\\victim\\Desktop\\test1.exe"
>>> print (data.decode(encoding))
C:\Users\victim\Desktop\test1.exe

或者,跳過編碼部分,只需將您的字符串定義為原始字符串:

data = r"C:\Users\victim\Desktop\test1.exe"

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM