KGBGUY
KGBGUY

Reputation: 29

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

Upvotes: 0

Views: 34

Answers (1)

tituszban
tituszban

Reputation: 5162

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"

Upvotes: 2

Related Questions