内置函数的未定义函数名?

时间:2013-09-19 11:49:18

标签: python python-3.x

ctext = "09e1c5f70a65ac519458e7e53f36"

text= "hello"
text2= "goodbye"

htext = asctohex(text)
print text,"=",htext,"=",binascii.unhexlify(htext)
print "and using encode()",text.encode('hex')
print

text2= asctohex(text2)
print text2,"=",text2,"=",binascii.unhexlify(text2)

otp = operator.xor(int(htext,16), int(ctext,16))

cDusk = operator.xor(int(text2,16), otp)

我收到以下错误。但是我认为asctohex是来自库的Python的内置函数吗?

Traceback (most recent call last):
File "dawnq.py", line 11, in <module>
 htext = asctohex(text)
NameError: name 'asctohex' is not defined

1 个答案:

答案 0 :(得分:1)

asctohex不是标准的Python函数。

您可能想要使用binascii.hexlify。 (此函数与您已使用的unhexlify相反。)

text = "hello"
hexVal = binascii.hexlify(text)
print text, " in hex is: ", hexVal