推荐学习书目
› 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 · 2112 views
    This topic created in 3781 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   ·   Privacy   ·   Solana   ·   821 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 28ms · UTC 22:25 · PVG 06:25 · LAX 15:25 · JFK 18:25
    ♥ Do have faith in what you're doing.