【发布时间】:2012-08-30 14:57:36
【问题描述】:
显然,通配符 %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()
【问题讨论】:
-
你希望用这条线完成什么?
\x<whatever>只会在字符串文字中做一些有用的事情;你不能那样使用字符串格式。
标签: python syntax-error wildcard