V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
imkh
V2EX  ›  Python

python dict 获取值问题

  •  
  •   imkh · May 31, 2016 · 1847 views
    This topic created in 3624 days ago, the information mentioned may be changed or developed.

    test = {u'Engine': u'MySQL', u'DBInstanceId': u'test', u'PerformanceKeys': {u'PerformanceKey': [{u'ValueFormat': u'cpuusage&memusage', u'Values': {u'PerformanceValue': [{u'Date': u'2016-05-31T14:20:09Z', u'Value': u'2.05&45.4'}]}, u'Unit': u'%', u'Key': u'MySQL_MemCpuUsage'}]}, u'RequestId': u'08AF543A-769A-4433-953E-685657D1678F', u'StartTime': u'2016-05-31T14:20Z', u'EndTime': u'2016-05-31T14:25Z'}

    这么一大段嵌套 dict ,有没有什么方法可以方便地获取 u'Value'的值?

    pimin
        1
    pimin  
       May 31, 2016   ❤️ 1
    这种情况不是很建议走近路
    感觉会带来很多问题
    一个一个节点遍历进去是最好的方式
    clino
        2
    clino  
       May 31, 2016 via Android   ❤️ 1
    test.get('k1', {}).get('k2')
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   1003 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 35ms · UTC 17:59 · PVG 01:59 · LAX 10:59 · JFK 13:59
    ♥ Do have faith in what you're doing.