在Python中将希伯来语字符串转换为十六进制

在Python中将希伯来语字符串转换为十六进制,python,unicode,hex,hebrew,Python,Unicode,Hex,Hebrew,我有一段代码,它用希伯来语输入一些字符串,并输出字符串的十六进制值 以下是我目前的代码: #!/usr/bin/env python # -*- coding: utf-8 -*- def str_to_hex(string): hex_str = "" '... some code ...' return hex_str my_input = raw_input("Enter string: ") hex_value = str_to_hex(my_input)

我有一段代码,它用希伯来语输入一些字符串,并输出字符串的十六进制值

以下是我目前的代码:

#!/usr/bin/env python
# -*- coding: utf-8 -*- 

def str_to_hex(string):
    hex_str = ""
    '... some code ...'
    return hex_str

my_input = raw_input("Enter string: ")
hex_value = str_to_hex(my_input)
print "Your String was: %s\t Hex Value:%s" % (my_input,hex_value)
print result.encode('utf-8')
有什么建议吗? 谢谢

您可以使用带有“hex”参数的
encode()

>>> 'blahblah'.encode('hex')
'626c6168626c6168'
你的职能是:

def str_to_hex(string):
    return string.encode('hex')
您可以使用带有“hex”参数的
encode()

>>> 'blahblah'.encode('hex')
'626c6168626c6168'
你的职能是:

def str_to_hex(string):
    return string.encode('hex')

下面是使用


下面是使用