在这种特殊情况下如何避免"ValueError:invalid\x escape"错误?

Joh*_*mBF 2 python wildcard syntax-error

显然,通配符%x不被识别为字节十六进制值,因此我得到错误"ValueError:invalid\x escape".

怎么避免这个?我不熟悉python.

for i in xrange(0,length):

  if i % 2 == 0:

    tempArray.append(unpack("B",payload_raw[x])[0]^key)
    x += 1

  else:

    randomByte = random.randint(65,90)
    tempArray.append(randomByte)

    for i in range(0,len(tempArray)):

      tempArray[i]="\x%x"%tempArray[i]

    for i in range(0,len(tempArray),15):

      outArray.append("\n'"+"".join(tempArray[i:i+15])+"'")
      outArray = "".join(outArray)
      devide = "i % 2;"
      open_structure = open(structure).read()
      code = open_structure % (junkA,outArray,junkB,key,length,devide)
      b.write(code)
      b.flush()
Run Code Online (Sandbox Code Playgroud)

Ign*_*ams 6

chr() 将为您提供0到255之间的值的字节字符串.

>>> chr(0xd3)
'\xd3'
Run Code Online (Sandbox Code Playgroud)