首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >如何在Python 2.7中从unicode字符串中删除\r、\n、\t

如何在Python 2.7中从unicode字符串中删除\r、\n、\t
EN

Stack Overflow用户
提问于 2018-06-21 08:56:41
回答 1查看 332关注 0票数 0

我有一些用恼人的转义字符填充的抓取数据:

代码语言:javascript
复制
{"website": "http://www.zebrawebworks.com/zebra/bluetavern/day.cfm?&year=2018&month=7&day=10", "headliner": ["\"Roda Vibe\" with the Tallahassee Choro Society"], "data": [" \r\n    ", "\r\n\t\r\n\r\n\t", "\r\n\t\r\n\t\r\n\t", "\r\n\t", "\r\n\t", "\r\n\t", "8:00 PM", "\r\n\t\r\n\tFEE:  $2 \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 ", "\r\n\tEvery 2nd & 4th Tuesday of the month, the Choro Society returns to Blue Tavern with that subtly infectious Brazilian rhythm and beautiful melodies that will stay with you for days. The perfect antidote to Taylor Swift. $2 for musicians; tips appreciated. ", "\r\n\t", "\r\n\t\r\n\t", "\r\n\t", "\r\n\t", "\r\n\t\r\n\t\r\n\r\n\t\r\n\t", "\r\n\t\r\n\t\t", "\r\n", "\r\n", "\r\n", "\r\n"]},

我正在尝试编写一个函数来删除这些字符,但我的两种策略都不起作用:

代码语言:javascript
复制
    # strategy 1
    escapes = ''.join([chr(char) for char in range(1, 32)])
    table = {ord(char): None for char in escapes}
    for item in concert['data']:
        item = item.translate(table)
    # strategy 2
    for item in concert['data']:
        for char in item:
            char = char.replace("\r", "").replace("\t", "").replace("\n", "")

为什么我的数据仍然充满了我尝试了两种不同方法删除的转义字符?

EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50958937

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档