I want to concatenate a hexadecimal digit hh with \x, to make a string "\xhh" that I will then put into a list and convert that into a long string. Here is my current code for that, which raises an error:
ValueError: invalid \x escape
This error makes sense to me, since I believe that \x has to be attached to something in order for the computer to recognize it, and I'm not sure how I can do that. I am wondering, would something like "\" + "x" + hh work, and also, is there a more efficient way of doing this?
Here is my code as it stands when it caused the error: (Note - volt, curr, and checksum values vary. I just put example values in for this)
voltValues = [30, 30, 30]
currValues = [30, 30, 30]
checksumValues = [39, 33]
v1 = "\x" + voltValues[0]
v2 = "\x" + voltValues[1]
v3 = "\x" + voltValues[2]
c1 = "\x" + currValues[0]
c2 = "\x" + currValues[1]
c3 = "\x" + currValues[2]
cs1 = "\x" + checksumValues[0]
cs2 = "\x" + checksumValues[1]
list = [ "\x01", "\x30", "\x53", v1, v2, v3, c1, c2, c3, "\x46", "\x46", "\x46", "\x30", "\x30", "\x30", "\x32", "\x46", "\x46", cs1, cs2, "\x0D" ]
return ''.join(list)
I want it to return "\x01\x30\x53\x30\x30\x30\x30\x30\x30\x46\x46\x46\x30\x30\x30\x32\x46\x46\x39\x33\x0D".
structmodule?