简体   繁体   中英

bytes and strings python

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

when I run it I get the following C:\Users[]ictim\Desktop est1.exe what I need to get is C:\Users\victim\Desktop\test1.exe

You'll need to escape the \ characters, otherwise it'll pick up on the character next to it and take it as a \t . Try:

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

Alternatively, skip the encoding part, and just define your string as raw:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM