gpt4 book ai didi

python - 编码python utf-8拆分

转载 作者:太空宇宙 更新时间:2023-11-04 00:43:07 24 4
gpt4 key购买 nike

我有一个变量:

age_expectations = dictionary['looking_for']['age']
print type(age_expectations), age_expectations

输出是:

<type 'unicode'> 22‑35

当我试图用破折号拆分它时,我遇到了以下问题:

res = age_expectations.split('-')
print res

输出如下:

[u'22\u201135']

代替:

["22", "35"]

问题是什么?我尝试了很多编码和解码,但不确定是否了解它是如何工作的。问题是否来自 split ?

最佳答案

使用unicodeunicode 分割成这样,

>>> u_code = u'\u0032\u0032\u2011\u0033\u0035'
>>> print u_code
22‑35
>>> u_code.split('-')
[u'22\u201135']
>>> u_code.split(u'\u2011')
[u'22', u'35']
>>>

关于python - 编码python utf-8拆分,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40995820/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com