【开源中国 APP 全新上线】“动弹” 回归、集成大模型对话、畅读技术报告”
这个应该是每个python新手都会遇到的问题把
一般的代码
string = u"\u5982\u679c"
print string
现在如果u后面的是未知的变量,如何让它也能达到上面的效果呢?
我试了u(变量)不行。。
【开源中国 APP 全新上线】“动弹” 回归、集成大模型对话、畅读技术报告”
这个应该是每个python新手都会遇到的问题把
一般的代码
string = u"\u5982\u679c"
print string
现在如果u后面的是未知的变量,如何让它也能达到上面的效果呢?
我试了u(变量)不行。。
你指的是什么?
如果你说的是:json像这种
>>> import json
>>> js = '{"one":"\u5982\u679c"}'
>>> type(js)
<type 'str'>
>>> js = json.JSONDecoder().decode(js)
>>> js
{u'one': u'\u5982\u679c'}
>>> type(js)
<type 'dict'>
>>> print js['one']
如果
>>> type(js['one'])
<type 'unicode'>
还是纯字符串:
>>> s = '\u5982\u679c'
>>> s = "u'%s'"%(s)
>>> s
"u'\\u5982\\u679c'"
>>> type(s)
<type 'str'>
>>> s = eval(s)
>>> type(s)
<type 'unicode'>
>>> print s
如果
参:http://fc-lamp.blog.163.com/blog/static/1745666872012121240969/
引用来自“Narky”的答案
这样子
unicode() 函数?
引用来自“伊藤熊吉”的答案
unicode() 函数?
引用来自“fc_lamp”的答案
你指的是什么?
如果你说的是:json像这种
>>> import json
>>> js = '{"one":"\u5982\u679c"}'
>>> type(js)
<type 'str'>
>>> js = json.JSONDecoder().decode(js)
>>> js
{u'one': u'\u5982\u679c'}
>>> type(js)
<type 'dict'>
>>> print js['one']
如果
>>> type(js['one'])
<type 'unicode'>
还是纯字符串:
>>> s = '\u5982\u679c'
>>> s = "u'%s'"%(s)
>>> s
"u'\\u5982\\u679c'"
>>> type(s)
<type 'str'>
>>> s = eval(s)
>>> type(s)
<type 'unicode'>
>>> print s
如果
参:http://fc-lamp.blog.163.com/blog/static/1745666872012121240969/