V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
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 · 2016-05-31 22:56:33 +08:00 · 1465 次点击
    这是一个创建于 2899 天前的主题,其中的信息可能已经有所发展或是发生改变。

    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  
       2016-05-31 23:05:06 +08:00   ❤️ 1
    这种情况不是很建议走近路
    感觉会带来很多问题
    一个一个节点遍历进去是最好的方式
    clino
        2
    clino  
       2016-05-31 23:32:57 +08:00 via Android   ❤️ 1
    test.get('k1', {}).get('k2')
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   3215 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 28ms · UTC 12:58 · PVG 20:58 · LAX 05:58 · JFK 08:58
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.