浙江省高等学校教师教育理论培训

微信搜索“教师资格证岗前培训”小程序

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

PYTHON实现 字符串转化为十六进制串 - 阿毛小猪 - 博客园

PYTHON实现 字符串转化为十六进制串

4| Ping  -> \34\7c\50\69\6e\67

处理以前的文档,有几十条数据都是给出了值而没有给出code,因此写了个小小的转换。用UltraEdit打开文件,这样调用一次,生成的两行数据复制起来很方便

def a(input):
    f = open('a.txt','a')  
    payload = ""
    code = ""
    for i in input:
        payload += ' '+hex(ord(i))[2:]
        code += '\\'+hex(ord(i))[2:]
    print payload
    print code
    print len(input)
    f.write(code +'\n')
    f.write(payload+'\n')

 相信PYTHON还有更多更牛的实现办法的^

posted on 2012-12-20 19:23  lexus  阅读(666)  评论(0编辑  收藏  举报