【发布时间】:2019-07-31 01:43:27
【问题描述】:
我正在调用 Gmail API 以获取电子邮件的标题。一些标题包含非字母数字字符,例如表情符号、“'”符号等(例如:'\u201cEthnographic')。同时我需要保留单词末尾的标点符号:例如Hello!需要保存。我已经看过许多关于如何摆脱非字母数字的代码示例,但无法完成我想要做的事情。任何反馈表示赞赏。
# Call the api and get the emails
M = json.dumps(message)
temp = message['messages'][0]['payload']
num_found = 0
# get the subject of the emails
for header in temp['headers']:
# print(header['name'])
if header['name'] == 'Subject':
subject = header['value']
break
# S contains patterns like "\u201cEthnographic ..."
# or "u2b50\ufe0f best of .."
S = json.dumps(subject)
【问题讨论】:
-
您是否针对您的输入 (json.dumps(subject)) 测试了以下示例?
标签: python-3.x gmail-api