免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2216 | 回复: 2
打印 上一主题 下一主题

python3 类型问题 求助? [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2009-06-02 23:11 |只看该作者 |倒序浏览
def _decodeHtmlEntity(s):
    '''十进制unicode转换'''
    import re
    result = s
    entityRe = '( &# (\\d{5}); )'
    entities = re.findall(entityRe, s)
    for entity in entities :
            result = result.replace(entity[0], int(entity[1]))
    return result

s = '&# 28504;&# 29614;&# 26575;'
print(_decodeHtmlEntity(s))

这是错误提示:
result = result.replace(entity[0], int(entity[1]))
TypeError: Can't convert 'int


entity[1]  这个是str类型! 想转化成int 类型! 再将int类型转换成unicode编码
路过的请大家留言。

[ 本帖最后由 seacoastboy 于 2009-6-3 08:25 编辑 ]

论坛徽章:
0
2 [报告]
发表于 2009-06-03 08:55 |只看该作者
py 2.x下可以用:
result = result.replace(entity[0], unichr(int(entity[1])))

py 3.x下取消了unichr,改用chr
result = result.replace(entity[0], chr(int(entity[1])))

论坛徽章:
0
3 [报告]
发表于 2009-06-03 08:58 |只看该作者
感谢 smallfish 的帮忙!加油
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP