title: How to avoid the "ValueError: invalid \x escape" error in this special case?
body: <p>Obviously the wildcard %x is not recognized as a byte hex value, so I get the error "ValueError: invalid \x escape".</p>
  
  <p>How to avoid this? I'm not familiar with python.</p>
  
  <pre class="lang-py prettyprint-override"><code>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()
  </code></pre>