I'm trying to convert a python string to a null terminated byte string. I don't need this string for use in my python program, but I need to have the string in this format and use this output somewhere else.
But basically, for example, I would like to convert the string "cat" to "\x63\x61\x74" if possible, in some way or another.
I wasn't able to find a suitable solution for this problem so far.
I have one possible solution, but I was wondering if there was a better way to do this. This just places the hex values in a list. Not in the exact format above, but similar outcome.
text = "asjknlkjsndfskjn"
hexlist = []
for i in range(0, len(str)):
hexlist.append(hex(ord(str[i:i+1])))
print(hexlist)
x, am I right?