Python论坛  - 讨论区

标题:[python-chinese] python 中如何将字符和 ASCII 码互转?

2006年02月14日 星期二 16:57

Neil chenrong2003 at gmail.com
Tue Feb 14 16:57:14 HKT 2006

比如我想实现 VBScript 类似这样的操作:

MsgBox(Asc("a"))
MsgBox(Chr(97))

这两句的结果分别是 97, "a"

请问在 python 中怎么写?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.exoweb.net/pipermail/python-chinese/attachments/20060214/0ed03c3b/attachment.htm

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

2006年02月14日 星期二 17:01

limodou limodou at gmail.com
Tue Feb 14 17:01:06 HKT 2006

On 2/14/06, Neil <chenrong2003 at gmail.com> wrote:
> 比如我想实现 VBScript 类似这样的操作:
>
> MsgBox(Asc("a"))

ord('a')

> MsgBox(Chr(97))
>
chr(97)

> 这两句的结果分别是 97, "a"
>
> 请问在 python 中怎么写?

建议多看一看built-in函数文档,多读几遍。

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

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

2006年02月14日 星期二 17:40

Neil chenrong2003 at gmail.com
Tue Feb 14 17:40:57 HKT 2006

多谢!

我目前  还没看完,大概看了 1/3 了,感觉收获挺大。要细细阅读,呵。


On 2/14/06, limodou <limodou at gmail.com> wrote:
>
> On 2/14/06, Neil <chenrong2003 at gmail.com> wrote:
> > 比如我想实现 VBScript 类似这样的操作:
> >
> > MsgBox(Asc("a"))
>
> ord('a')
>
> > MsgBox(Chr(97))
> >
> chr(97)
>
> > 这两句的结果分别是 97, "a"
> >
> > 请问在 python 中怎么写?
>
> 建议多看一看built-in函数文档,多读几遍。
>
> --
> I like python!
> My Blog: http://www.donews.net/limodou
> 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
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.exoweb.net/pipermail/python-chinese/attachments/20060214/2f359c32/attachment.htm

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

2006年02月14日 星期二 17:46

Andelf andelf at gmail.com
Tue Feb 14 17:46:58 HKT 2006

chr(i)
将一个0到255的整数转换为一个字符.
ord(c)
返回单个字符c的整数顺序值.普通字符返回[0,255]中的一个值,Unicode字符返回 [0,65535]中的一个值
unichr(i)
将一个0到65535的整数转换为一个Unicode字符
是不是这个?

在06-2-14,Neil <chenrong2003 at gmail.com> 写道:
>
> 多谢!
>
> 我目前  还没看完,大概看了 1/3 了,感觉收获挺大。要细细阅读,呵。
>
>
>  On 2/14/06, limodou <limodou at gmail.com> wrote:
>
> > On 2/14/06, Neil <chenrong2003 at gmail.com> wrote:
> > > 比如我想实现 VBScript 类似这样的操作:
> > >
> > > MsgBox(Asc("a"))
> >
> > ord('a')
> >
> > > MsgBox(Chr(97))
> > >
> > chr(97)
> >
> > > 这两句的结果分别是 97, "a"
> > >
> > > 请问在 python 中怎么写?
> >
> > 建议多看一看built-in函数文档,多读几遍。
> >
> > --
> > I like python!
> > My Blog: http://www.donews.net/limodou
> > 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
>
>


--
Andelf
BLOG:http://blog.sohu.com/members/andelf/
BLOG:http://spaces.msn.com/members/andelf
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.exoweb.net/pipermail/python-chinese/attachments/20060214/371fdd1d/attachment-0001.htm

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

2006年02月14日 星期二 18:12

Neil chenrong2003 at gmail.com
Tue Feb 14 18:12:49 HKT 2006

thanks, Andalf. That's exactly what I what.

On 2/14/06, Andelf <andelf at gmail.com> wrote:
>
> chr(i)
> 将一个0到255的整数转换为一个字符.
> ord(c)
> 返回单个字符c的整数顺序值.普通字符返回[0,255]中的一个值,Unicode字符返回 [0,65535]中的一个值
> unichr(i)
> 将一个0到65535的整数转换为一个Unicode字符
> 是不是这个?
>
> 在06-2-14,Neil <chenrong2003 at gmail.com> 写道:
> >
> >  多谢!
> >
> > 我目前  还没看完,大概看了 1/3 了,感觉收获挺大。要细细阅读,呵。
> >
> >
> >  On 2/14/06, limodou < limodou at gmail.com> wrote:
> >
> > > On 2/14/06, Neil <chenrong2003 at gmail.com> wrote:
> > > > 比如我想实现 VBScript 类似这样的操作:
> > > >
> > > > MsgBox(Asc("a"))
> > >
> > > ord('a')
> > >
> > > > MsgBox(Chr(97))
> > > >
> > > chr(97)
> > >
> > > > 这两句的结果分别是 97, "a"
> > > >
> > > > 请问在 python 中怎么写?
> > >
> > > 建议多看一看built-in函数文档,多读几遍。
> > >
> > > --
> > > I like python!
> > > My Blog: http://www.donews.net/limodou
> > > 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
> >
> >
>
>
> --
> Andelf
> BLOG:http://blog.sohu.com/members/andelf/
> BLOG:http://spaces.msn.com/members/andelf
> _______________________________________________
> 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/20060214/d17edff8/attachment.html

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

2006年02月17日 星期五 09:32

Leo Jay python.leojay at gmail.com
Fri Feb 17 09:32:20 HKT 2006

On 2/14/06, Neil <chenrong2003 at gmail.com> wrote:
> 比如我想实现 VBScript 类似这样的操作:
>
> MsgBox(Asc("a"))
> MsgBox(Chr(97))
>
> 这两句的结果分别是 97, "a"
>
> 请问在 python 中怎么写?

还有一个库binascii很好用的,可以批量转换:
>>> import binascii
>>> binascii.b2a_hex('leo')
'6c656f'
>>> binascii.a2b_hex('6c656f')
'leo'

--
Best Regards,
Leo Jay

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

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

    你的回复:

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

    Zeuux © 2025

    京ICP备05028076号