【发布时间】:2018-01-26 11:49:56
【问题描述】:
Python 新手,Python 版本:2.7.10,机器:Mac OS Sierra。
Susi Sushanti Don $ python -c "import sys, json; print(json.load(open('/tmp/2.json'))['pages'])"
{u'giga-10': [u'overview']}
Susi Sushanti Don $ python -c "import sys, json; print(str(json.load(open('/tmp/2.json'))['pages']))"
{u'giga-10': [u'overview']}
为什么即使我使用了str(),python 仍然打印u 字符?我在其他帖子中读到,使用字符串不会在 std 输出中打印它。是否有任何类似的 str() 函数可以在任何 Python 数据对象上工作(而不是自己编写可重用函数)?
我希望输出只是{'giga-10': ['overview']}
【问题讨论】:
-
这里的
str绝对什么都不做。print隐式使用str -
另外,“使用字符串不会在标准输出中打印它”是不正确的。我不确定你读到了什么,但它要么是错误的,要么是你误解了。
-
1.你确定你有python链接到python2.7而不是python3吗? 2.你的当前文件夹中有
__init__.py文件吗? -
@Dekel 绝对是 Python 2。
标签: python python-2.7 unicode jq python-unicode