Python论坛  - 讨论区

标题:[python-chinese] 请教一下如何将16进制转换为字符串?

2006年08月09日 星期三 14:40

隋刚 blackjacksg at gmail.com
Wed Aug 9 14:40:04 HKT 2006

   我从数据库中取出的数据跟具体的文件名有关系,但是这个数据是16进制的,不知道谁有比较好的办法把16进制转换为相应的字符串?

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

2006年08月09日 星期三 14:45

wangmm kernellearn at gmail.com
Wed Aug 9 14:45:16 HKT 2006

hex(i)

On 8/9/06, 隋刚 <blackjacksg at gmail.com> wrote:
>
>    我从数据库中取出的数据跟具体的文件名有关系,但是这个数据是16进制的,不知道谁有比较好的办法把16进制转换为相应的字符串?
>
> _______________________________________________
> python-chinese
> Post: send python-chinese at lists.python.cn
> Subscribe: send subscribe to python-chinese-request at lists.python.cn
> Unsubscribe: send unsubscribe to  python-chinese-request at lists.python.cn
> Detail Info: http://python.cn/mailman/listinfo/python-chinese
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.exoweb.net/pipermail/python-chinese/attachments/20060809/12645aef/attachment.html

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

2006年08月09日 星期三 15:00

隋刚 blackjacksg at gmail.com
Wed Aug 9 15:00:05 HKT 2006

谢谢,问题解决了。

在 06-8-9,wangmm<kernellearn at gmail.com> 写道:
> hex(i)
>
> On 8/9/06, 隋刚 <blackjacksg at gmail.com> wrote:
> >
> 我从数据库中取出的数据跟具体的文件名有关系,但是这个数据是16进制的,不知道谁有比较好的办法把16进制转换为相应的字符串?
> >
> > _______________________________________________
> > python-chinese
> > Post: send python-chinese at lists.python.cn
> > Subscribe: send subscribe to
> python-chinese-request at lists.python.cn
> > Unsubscribe: send unsubscribe to
> python-chinese-request at lists.python.cn
> > Detail Info:
> http://python.cn/mailman/listinfo/python-chinese
> >
> >
>
>
> _______________________________________________
> python-chinese
> Post: send python-chinese at lists.python.cn
> Subscribe: send subscribe to
> python-chinese-request at lists.python.cn
> Unsubscribe: send unsubscribe to
> python-chinese-request at lists.python.cn
> Detail Info:
> http://python.cn/mailman/listinfo/python-chinese
>
>

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

2006年08月09日 星期三 15:34

隋刚 blackjacksg at gmail.com
Wed Aug 9 15:34:34 HKT 2006

出来是字符串,可是因为里面有特殊字符,不能够很好的打印了,原字符串如下:
'\x00\x91\xe2\xbe\xf1\x00\x04\xc4\x94\xba\xf7\xa2\x11\xf7\x11f\xe4A\x1c\xcc'
想转换为
'0091E2BEF10004C494BAF7A211F71166E4411CCC'打印出来应该如何做?谢谢。

在 06-8-9,隋刚<blackjacksg at gmail.com> 写道:
> 谢谢,问题解决了。
>
> 在 06-8-9,wangmm<kernellearn at gmail.com> 写道:
> > hex(i)
> >
> > On 8/9/06, 隋刚 <blackjacksg at gmail.com> wrote:
> > >
> > 我从数据库中取出的数据跟具体的文件名有关系,但是这个数据是16进制的,不知道谁有比较好的办法把16进制转换为相应的字符串?
> > >
> > > _______________________________________________
> > > python-chinese
> > > Post: send python-chinese at lists.python.cn
> > > Subscribe: send subscribe to
> > python-chinese-request at lists.python.cn
> > > Unsubscribe: send unsubscribe to
> > python-chinese-request at lists.python.cn
> > > Detail Info:
> > http://python.cn/mailman/listinfo/python-chinese
> > >
> > >
> >
> >
> > _______________________________________________
> > python-chinese
> > Post: send python-chinese at lists.python.cn
> > Subscribe: send subscribe to
> > python-chinese-request at lists.python.cn
> > Unsubscribe: send unsubscribe to
> > python-chinese-request at lists.python.cn
> > Detail Info:
> > http://python.cn/mailman/listinfo/python-chinese
> >
> >
>

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

2006年08月09日 星期三 16:00

limodou limodou at gmail.com
Wed Aug 9 16:00:14 HKT 2006

On 8/9/06, 隋刚 <blackjacksg at gmail.com> wrote:
> 出来是字符串,可是因为里面有特殊字符,不能够很好的打印了,原字符串如下:
> '\x00\x91\xe2\xbe\xf1\x00\x04\xc4\x94\xba\xf7\xa2\x11\xf7\x11f\xe4A\x1c\xcc'
> 想转换为
> '0091E2BEF10004C494BAF7A211F71166E4411CCC'打印出来应该如何做?谢谢。
>
 >>> a= '\x00\x91\xe2\xbe\xf1\x00\x04\xc4\x94\xba\xf7\xa2\x11\xf7\x11f\xe4A\x1c\xcc'
 >>> import binascii
 >>> binascii.b2a_hex(a)
 '0091e2bef10004c494baf7a211f71166e4411ccc'

-- 
I like python!
My Blog: http://www.donews.net/limodou
My Django Site: http://www.djangocn.org
NewEdit Maillist: http://groups.google.com/group/NewEdit

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

2006年08月09日 星期三 16:04

隋刚 blackjacksg at gmail.com
Wed Aug 9 16:04:24 HKT 2006

非常感谢,呵呵。

在 06-8-9,limodou<limodou at gmail.com> 写道:
> On 8/9/06, 隋刚 <blackjacksg at gmail.com> wrote:
> > 出来是字符串,可是因为里面有特殊字符,不能够很好的打印了,原字符串如下:
> > '\x00\x91\xe2\xbe\xf1\x00\x04\xc4\x94\xba\xf7\xa2\x11\xf7\x11f\xe4A\x1c\xcc'
> > 想转换为
> > '0091E2BEF10004C494BAF7A211F71166E4411CCC'打印出来应该如何做?谢谢。
> >
>  >>> a= '\x00\x91\xe2\xbe\xf1\x00\x04\xc4\x94\xba\xf7\xa2\x11\xf7\x11f\xe4A\x1c\xcc'
>  >>> import binascii
>  >>> binascii.b2a_hex(a)
>  '0091e2bef10004c494baf7a211f71166e4411ccc'
>
> --
> I like python!
> My Blog: http://www.donews.net/limodou
> My Django Site: http://www.djangocn.org
> NewEdit Maillist: http://groups.google.com/group/NewEdit
>
> _______________________________________________
> python-chinese
> Post: send python-chinese at lists.python.cn
> Subscribe: send subscribe to python-chinese-request at lists.python.cn
> Unsubscribe: send unsubscribe to  python-chinese-request at lists.python.cn
> Detail Info: http://python.cn/mailman/listinfo/python-chinese
>
>

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

2006年08月09日 星期三 21:03

fu wenxiang fuwenxiang1982 at gmail.com
Wed Aug 9 21:03:18 HKT 2006

我看了binascii库,这几个编码有什么差别。
>>> binascii.b2a_hqx(a)
'!*(L[[%!"-58Z[HL%IF4CZ4"(-`'
>>> binascii.rlecode_hqx(a)
'\x00\x91\xe2\xbe\xf1\x00\x04\xc4\x94\xba\xf7\xa2\x11\xf7\x11f\xe4A\x1c\xcc'
>>> binascii.b2a_base64(a)
'AJHivvEABMSUuveiEfcRZuRBHMw=\n'


----- Original Message ----- 
From: "隋刚" <blackjacksg at gmail.com>
To: <python-chinese at lists.python.cn>
Sent: Wednesday, August 09, 2006 4:04 PM
Subject: Re: [python-chinese] 请教一下如何将16进制转换为字符串?


> 非常感谢,呵呵。
> 
> 在 06-8-9,limodou<limodou at gmail.com> 写道:
>> On 8/9/06, 隋刚 <blackjacksg at gmail.com> wrote:
>> > 出来是字符串,可是因为里面有特殊字符,不能够很好的打印了,原字符串如下:
>> > '\x00\x91\xe2\xbe\xf1\x00\x04\xc4\x94\xba\xf7\xa2\x11\xf7\x11f\xe4A\x1c\xcc'
>> > 想转换为
>> > '0091E2BEF10004C494BAF7A211F71166E4411CCC'打印出来应该如何做?谢谢。
>> >
>>  >>> a= '\x00\x91\xe2\xbe\xf1\x00\x04\xc4\x94\xba\xf7\xa2\x11\xf7\x11f\xe4A\x1c\xcc'
>>  >>> import binascii
>>  >>> binascii.b2a_hex(a)
>>  '0091e2bef10004c494baf7a211f71166e4411ccc'
>>
>> --
>> I like python!
>> My Blog: http://www.donews.net/limodou
>> My Django Site: http://www.djangocn.org
>> NewEdit Maillist: http://groups.google.com/group/NewEdit
>>
>> _______________________________________________
>> python-chinese
>> Post: send python-chinese at lists.python.cn
>> Subscribe: send subscribe to python-chinese-request at lists.python.cn
>> Unsubscribe: send unsubscribe to  python-chinese-request at lists.python.cn
>> Detail Info: http://python.cn/mailman/listinfo/python-chinese
>>
>>
>


--------------------------------------------------------------------------------


> _______________________________________________
> python-chinese
> Post: send python-chinese at lists.python.cn
> Subscribe: send subscribe to python-chinese-request at lists.python.cn
> Unsubscribe: send unsubscribe to  python-chinese-request at lists.python.cn
> Detail Info: http://python.cn/mailman/listinfo/python-chinese

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

2006年08月09日 星期三 21:46

limodou limodou at gmail.com
Wed Aug 9 21:46:02 HKT 2006

On 8/9/06, fu wenxiang <fuwenxiang1982 at gmail.com> wrote:
> 我看了binascii库,这几个编码有什么差别。
> >>> binascii.b2a_hqx(a)
> '!*(L[[%!"-58Z[HL%IF4CZ4"(-`'
> >>> binascii.rlecode_hqx(a)
> '\x00\x91\xe2\xbe\xf1\x00\x04\xc4\x94\xba\xf7\xa2\x11\xf7\x11f\xe4A\x1c\xcc'
> >>> binascii.b2a_base64(a)
> 'AJHivvEABMSUuveiEfcRZuRBHMw=\n'
>
base64知道,其它的不知道,看文档吧。

-- 
I like python!
My Blog: http://www.donews.net/limodou
My Django Site: http://www.djangocn.org
NewEdit Maillist: http://groups.google.com/group/NewEdit

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

如下红色区域有误,请重新填写。

    你的回复:

    请 登录 后回复。还没有在Zeuux哲思注册吗?现在 注册 !

    Zeuux © 2025

    京ICP备05028076号