import requests
r = requests.get('some url')
data = r.text
{“ NumberOfPassedStudents”:“ 21061”,“ TotalAttendedCandidates”:“ 74494”,“ NumberOfEnrolledStudents”:“ 84308”}
我得到的上述输出看起来像
dictionary
,但不是dictionary
而是Unicode
。我的问题是我想以下述方式获取输出通过学生人数:21061
参会人数:74494
招生人数:84308
python 2.7中将这些Unicode转换成我期望的上述输出的代码是什么?
最佳答案
import re
data={"NumberOfPassedStudents":"21061","TotalAttendedCandidates":"74494","NumberOfEnrolledStudents":"84308"}
for k,v in data.iteritems():
print re.sub(r"(\w)([A-Z])", r"\1 \2",k) +" : "+ v
输出
Number Of Passed Students : 21061
Total Attended Candidates : 74494
Number Of Enrolled Students : 84308