繁体   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